MySQL 5.5 range分区增加删除处理的方法示例

作者:andylhz 时间:2024-01-22 21:16:19 

介绍

RANGE分区基于一个给定的连续区间范围,早期版本RANGE主要是基于整数的分区。在5.7版本中DATE、DATETIME列也可以使用RANGE分区,同时在5.5以上的版本提供了基于非整形的RANGE COLUMN分区。RANGE分区必须的连续的且不能重叠。使用

“VALUES LESS THAN ()” 来定义分区区间,非整形的范围值需要使用单引号,并且可以使用MAXVALUE作为分区的最高值。

本文将给大家介绍MySQL 5.5 range分区增加删除处理的相关内容,分享给大家供大家参考学习,下面来看看详细的介绍:

一、删除分区


##查看要处理的分区的数据量,并导出作为备份

mysql> select count(*) from baby_account_change_log where updated_time >'2016-12-01 00:00:00' and updated_time <'2017-01-01 00:00:00';
+----------+
| count(*) |
+----------+
| 66252 |
+----------+
1 row in set (0.23 sec)

##导出备份

mysql> select * into outfile '/tmp/baby_account_change_log_p1.sql' from baby_account_change_log where updated_time >'2016-12-01 00:00:00' and updated_time <'2017-01-01 00:00:00' limit 100000000000;
Query OK, 66252 rows affected (2.71 sec)

##确认要处理分区

mysql> explain partitions select count(*) from baby_account_change_log where updated_time >'2016-12-01 00:00:00' and updated_time <'2017-01-01 00:00:00';

+----+-------------+-------------------------------+------------+-------+---------------+---------+---------+------+-------+--------------------------+
| id | select_type | table       | partitions | type | possible_keys | key  | key_len | ref | rows | Extra     |
+----+-------------+-------------------------------+------------+-------+---------------+---------+---------+------+-------+--------------------------+
| 1 | SIMPLE  | baby_account_change_log | p1   | index | NULL   | PRIMARY | 8  | NULL | 66252 | Using where; Using index |
+----+-------------+-------------------------------+------------+-------+---------------+---------+---------+------+-------+--------------------------+

##删除分区

mysql> alter table baby_account_change_log drop partition p0;
Query OK, 0 rows affected (0.01 sec)

二、增加分区


#错误提示删除存储最大值分区
mysql> alter table baby_account_change_log add partition(PARTITION p13 VALUES LESS THAN (unix_timestamp('2017-12-31 23:59:59')));
ERROR 1481 (HY000): MAXVALUE can only be used in last partition definition

#删除存储最大值分区
mysql> alter table baby_account_change_log drop partition p12;

##增加新的分区

mysql> alter table baby_account_change_log add partition(PARTITION p12 VALUES LESS THAN (unix_timestamp('2017-12-31 23:59:59')));

来源:http://andylhz2009.blog.51cto.com/728703/1931929

标签:mysql,range,分区
0
投稿

猜你喜欢

  • python调用百度地图WEB服务API获取地点对应坐标值

    2021-06-05 18:21:28
  • js实现楼层效果的简单实例

    2024-06-07 15:26:01
  • js实现局部页面打印预览原理及示例代码

    2024-04-25 13:13:48
  • python实现求解列表中元素的排列和组合问题

    2022-03-18 00:05:08
  • Go语言开发编程规范命令风格代码格式

    2024-05-22 10:15:03
  • Python入门教程5. 字典基本操作【定义、运算、常用函数】 <font color=red>原创</font>

    2021-04-29 19:08:04
  • 通过python连接Linux命令行代码实例

    2023-01-25 23:10:33
  • 异地远程访问本地SQL Server数据库

    2024-01-18 20:00:18
  • 详解Golang实现http重定向https的方式

    2024-05-09 09:47:02
  • Python中的True,False条件判断实例分析

    2023-09-30 07:34:24
  • chr()函数参照表 chr13 chr10 chr34

    2009-09-03 13:22:00
  • js省市联动效果完整实例代码

    2024-04-18 10:15:34
  • mysql如何通过my.ini更改默认字符集

    2024-01-28 08:25:07
  • MySQL触发器trigger的使用

    2024-01-23 15:08:23
  • Python中Collection的使用小技巧

    2022-04-14 01:42:57
  • Python代码模拟CPU工作原理

    2023-08-04 15:23:49
  • 解决python将xml格式文件转换成txt文件的问题(xml.etree方法)

    2021-10-21 02:51:13
  • 先学会为自己做设计

    2008-06-01 16:32:00
  • python使用requests实现发送带文件请求功能

    2023-11-03 14:23:13
  • MySQL里的反斜杠(\\\\)的使用

    2024-01-26 03:20:57
  • asp之家 网络编程 m.aspxhome.com