当前位置: 移动技术网 > IT编程>数据库>Mysql > MySQL 5.5 range分区增加删除处理的方法示例

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

介绍

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')));

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对移动技术网的支持。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网