【MYSQL】修改分区规则时遇到的问题及解决办法
开始分区时的规则为:PARTITION pt1 VALUES LESS THAN (1000000000)
PARTITION pt2 VALUES LESS THAN (2000000000)
PARTITION pt3 VALUES LESS THAN MAXVALUE
后来想将规则改为:PARTITION pt1 VALUES LESS THAN (10)
PARTITION pt2 VALUES LESS THAN (20)
PARTITION pt3 VALUES LESS THAN MAXVALUE
就执行了下面的SQL文:
ALTER TABLE accounts REORGANIZE PARTITION pt1 INTO
(PARTITION pt1 VALUES LESS THAN (10) COMMENT 'host "127.0.0.1", port "6001"');
结果出现错误:
Mysql::Error: Reorganize of range partitions cannot change total ranges except for last partition where it can extend the range: alter table accounts reorganize partition pt1 into( partition pt1 values less than (10) );
这个错误的意思大致是指:
该重编Range分区规则的SQL文不能改变整个ranges,MySQL期待全范围分区规则的重编。
可能MySQL觉得只修改一个规则,会导致整个accounts表的分区规则出现漏洞吧。。。
后来将SQL改为如下所示,即可执行成功:
ALTER TABLE accounts REORGANIZE PARTITION pt1,pt2,pt3 INTO
( PARTITION pt1 VALUES LESS THAN (10) COMMENT 'host "127.0.0.1", port "6001"',
PARTITION pt2 VALUES LESS THAN (20) COMMENT 'host "127.0.0.1", port "6002"',
PARTITION pt3 VALUES LESS THAN MAXVALUE COMMENT 'host "127.0.0.1", port "6003"'
);