首页 > 数据库技术 > 详细

Mysql 表分区

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

创建分区表:

 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 表分区

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!