mysql 增加range分区,MySQL5.5 RANGE分区增加删除处理

本文介绍MySQL中分区操作的具体步骤,包括如何查看并备份指定日期后的数据记录,如何删除及新增分区,以及解决常见错误提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、删除分区

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

mysql> select count(*)  from baby_account_change_log where updated_time >‘2016-12-01 00:00:00‘ and updated_time

+----------+

| 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

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

+----+-------------+-------------------------------+------------+-------+---------------+---------+---------+------+-------+--------------------------+

| 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值