首页 > 代码库 > Mysql 表分区
Mysql 表分区
创建分区表:
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 表分区
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。