一個大表,之前是以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
|
現在要把分區去掉,怎麼去呢?
檢視文法如下:
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 |
表分區消失,完成。
MySQL-如何删除hash表分區
标簽:clock 完成 format char query mysql 表分區 schema 如何
本條技術文章來源于網際網路,如果無意侵犯您的權益請點選此處回報版權投訴
本文系統來源:https://www.cnblogs.com/xiaoyanger/p/8137203.html