MySQL5.5 如何分区增加删除处理
本文主要给大家介绍MySQL5.5 如何分区增加删除处理,希望可以给大家补充和更新些知识,如有其它问题需要了解的可以持续在亿速云行业资讯里面关注我的更新文章的。
一、删除分区
##查看要处理的分区的数据量,并导出作为备份
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')));
看了以上关于MySQL5.5 如何分区增加删除处理,希望能给大家在实际运用中带来一定的帮助。本文由于篇幅有限,难免会有不足和需要补充的地方,如有需要更加专业的解答,可在官网联系我们的24小时售前售后,随时帮您解答问题的。