MySQL-如何刪除hash表分區


一個大表,之前是以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 |

  

表分區消失,完成。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM