码迷,mamicode.com
首页 > 数据库 > 详细

Mysql 表分区

时间:2016-11-26 23:45:45      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:add   tab   style   inf   des   esc   添加分区   alter   最大   

创建分区表:

 DELIMITER // 

create table VMMoniterData (
    id_ bigint not null AUTO_INCREMENT,
    vmid varchar(75) null,
    cpu varchar(75) null,
    memory varchar(75) null,
    bpsRead varchar(75) null,
    bpsWrite varchar(75) null,
    intranetRX0 varchar(75) null,
    intranetRX1 varchar(75) null,
    intranetWX0 varchar(75) null,
    intranetWX1 varchar(75) null,
    timeStamp datetime null,
    PRIMARY KEY (id_,timeStamp)
) engine InnoDB

PARTITION BY RANGE (TO_DAYS(timeStamp) ) (
    PARTITION p1 VALUES LESS THAN ( TO_DAYS(‘20161101‘) ),
    PARTITION p2 VALUES LESS THAN ( TO_DAYS(‘20161102‘) ),
    PARTITION p3 VALUES LESS THAN ( TO_DAYS(‘20161103‘) ),
    PARTITION p4 VALUES LESS THAN ( TO_DAYS(‘20161104‘) ),
    PARTITION p5 VALUES LESS THAN ( TO_DAYS(‘20161105‘) ),
    PARTITION p6 VALUES LESS THAN ( TO_DAYS(‘20161106‘) ),
    PARTITION p7 VALUES LESS THAN ( TO_DAYS(‘20161107‘) ),
    PARTITION p8 VALUES LESS THAN ( TO_DAYS(‘20161108‘) ),
    PARTITION p9 VALUES LESS THAN ( TO_DAYS(‘20161109‘) ),
    PARTITION p10 VALUES LESS THAN ( TO_DAYS(‘20161110‘) )
);

//
DELIMITER ;

添加分区表:

ALTER TABLE VMMoniterData ADD PARTITION(PARTITION p315 VALUES LESS THAN (TO_DAYS(‘22190527‘)));

查看表分区情况:

SELECT
  partition_name part, 
  partition_expression expr, 
  partition_description descr, 
  table_rows 
FROM
  INFORMATION_SCHEMA.partitions 
WHERE
  TABLE_SCHEMA = schema() 
  AND TABLE_NAME=‘VMMoniterData‘; 

添加分区最大值

ALTER TABLE VMMoniterData ADD PARTITION (PARTITION p11 VALUES LESS THAN maxvalue);

每天自动添加分区

 

Mysql 表分区

标签:add   tab   style   inf   des   esc   添加分区   alter   最大   

原文地址:http://www.cnblogs.com/langdangyunliu/p/6105271.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!