• mysql创建表分区


    MySQL创建表分区

    create table erp_bill_index(
        id int primary key auto_increment,
        addtime datetime
    );
    insert into erp_bill_index(addtime) 
    values
    ('2018-02-01 12:00:00'),
    ('2018-03-01 12:00:00'),
    ('2018-04-01 12:00:00'),
    ('2018-05-01 12:00:00'),
    ('2018-06-01 12:00:00'),
    ('2018-07-01 12:00:00'),
    ('2018-08-01 12:00:00'),
    ('2018-09-01 12:00:00'),
    ('2018-10-01 12:00:00'),
    ('2018-11-01 12:00:00'),
    ('2018-12-01 12:00:00'),
    ('2019-01-01 12:00:00'),
    ('2019-02-01 12:00:00'),
    ('2019-03-01 12:00:00'),
    ('2019-04-01 12:00:00'),
    ('2019-05-01 12:00:00'),
    ('2019-06-01 12:00:00'),
    ('2019-07-01 12:00:00'),
    ('2019-08-01 12:00:00'),
    ('2019-09-01 12:00:00'),
    ('2019-10-01 12:00:00'),
    ('2019-11-01 12:00:00'),
    ('2019-12-01 12:00:00');
    
    alter table erp_bill_index drop primary key;-- 删除主键,在删除主键的时候,这个自增会让该语句执行失败,先取消字段自增,然后执行该语句后,再加上自增
    alter table erp_bill_index add primary key(id,addtime);-- 添加主键,(分区要求:分区中使用的字段必须都包含在主键当中)
    
    -- 创建分区(分区要求:分区中使用的字段必须都包含在主键当中)
    ALTER TABLE erp_bill_index PARTITION by RANGE(to_days(addtime))
    (
      PARTITION p201801 VALUES LESS THAN (to_days('2018-02-01')),
      PARTITION p201802 VALUES LESS THAN (to_days('2018-03-01')),
      PARTITION p201803 VALUES LESS THAN (to_days('2018-04-01')),
      PARTITION p201804 VALUES LESS THAN (to_days('2018-05-01')),
      PARTITION p201805 VALUES LESS THAN (to_days('2018-06-01')),
      PARTITION p201806 VALUES LESS THAN (to_days('2018-07-01')),
      PARTITION p201807 VALUES LESS THAN (to_days('2018-08-01')),
      PARTITION p201808 VALUES LESS THAN (to_days('2018-09-01')),
      PARTITION p201809 VALUES LESS THAN (to_days('2018-10-01')),
      PARTITION p201810 VALUES LESS THAN (to_days('2018-11-01')),
      PARTITION p201811 VALUES LESS THAN (to_days('2018-12-01')),
      PARTITION p201812 VALUES LESS THAN (to_days('2019-01-01')),
      PARTITION p201901 VALUES LESS THAN (to_days('2019-02-01')),
      PARTITION p201902 VALUES LESS THAN (to_days('2019-03-01')),
      PARTITION p201903 VALUES LESS THAN (to_days('2019-04-01')),
      PARTITION p300012 VALUES LESS THAN (9223372036854775807) -- 剩下的放在一个分区中,当需要对这部分进行再次分区的时候,需要先删除该分区,然后再添加多个分区
    );
    
    
    -- 删除分区
    ALTER TABLE erp_bill_index DROP PARTITION p300012;
    -- 添加新的分区
    alter table erp_bill_index add PARTITION
    (
        PARTITION p201905 VALUES LESS THAN (to_days('2019-06-01')) ENGINE = InnoDB,
        PARTITION p300012 VALUES LESS THAN (9223372036854775807)
    );

    mysql执行分析参考:https://blog.csdn.net/weixin_45310179/article/details/99591496
  • 相关阅读:
    MySQL根据表前缀批量修改、删除表
    SpringBoot如何打印带参数的sql和执行时间p6spy
    linux指令查找字符串所在行,输出行号
    金蝶云星空常用数据表
    java基础复习流水账
    Vue脚手架——手把手教你安装和使用
    Vue2脚手架安装 百度
    什么是面向对象编程?用自己的话说出来讲出来
    methods属性 就是里面写方法的属性 computed是里面写计算的属性
    vue零基础 基础教程P5第05节:计算属性与侦听器
  • 原文地址:https://www.cnblogs.com/TheoryDance/p/11719572.html
Copyright © 2020-2023  润新知