一个大表,之前是以hash分区表的形式存在的,
MySQL> show create table history_uint; | history_uint | CREATE TABLE `history_uint` (
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`value` bigint(20) unsigned NOT NULL DEFAULT '0',
`ns` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`itemid`,`clock`,`ns`),
KEY `i_clock` (`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY HASH (itemid)
PARTITIONS 512 */ |
现在要把分区去掉,怎么去呢?
查看语法如下:
Alter table table coalesce partition num; num是指想要去除的表分区个数
那现在有512个分区,最后这个表我还是要的呀,所以尝试下,去除掉511个分区看看(当然,线上操作之前我已经在测试库中测试过了!!!线上操作需谨慎!!!)
MySQL> Alter table history_uint coalesce partition 511;
Query OK, 0 rows affected (4 min 41.71 sec)
操作后查看,果然,只剩下一个分区了
MySQL> SELECT TABLE_NAME, PARTITION_NAME ,TABLE_ROWS FROM information_schema.PARTITIONS WHERE TABLE_NAME='history_uint';
+--------------+----------------+------------+
| TABLE_NAME | PARTITION_NAME | TABLE_ROWS |
+--------------+----------------+------------+
| history_uint | p0 | 34909051 |
+--------------+----------------+------------+
1 row in set (0.01 sec)
接下来把这一个分区去掉就好了,注意要用remove,别用drop,用drop会将分区及数据一起删掉
MySQL> alter table history_uint REMOVE PARTITIONING;
Query OK, 0 rows affected (3 min 52.38 sec)
最后查看表结构
mysql> show create table history_uint; | history_uint | CREATE TABLE `history_uint` (
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`value` bigint(20) unsigned NOT NULL DEFAULT '0',
`ns` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`itemid`,`clock`,`ns`),
KEY `i_clock` (`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
表分区消失,完成。