zoukankan      html  css  js  c++  java
  • 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 |
    

      

    表分区消失,完成。

  • 相关阅读:
    03-java实现双向链表
    04-java实现循环链表
    02-java实现单链表
    01-java实现动态数组
    安装mpi的那些坑
    gotoblas,mpich,hpl,hpcg的安装
    centos之hadoop的安装
    公告
    AFO之后……
    Codeforces Round #599 (Div. 2)的简单题题解
  • 原文地址:https://www.cnblogs.com/xiaoyanger/p/8137203.html
Copyright © 2011-2022 走看看