资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

MySQL中怎么实现表分区功能

今天就跟大家聊聊有关MySQL中怎么实现表分区功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于做网站、成都网站制作、鸠江网络推广、成都微信小程序、鸠江网络营销、鸠江企业策划、鸠江品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联为所有大学生创业者提供鸠江建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com

MySQL表分区功能基础
创建分区表
CREATE TABLE `表名` (
`EQUIPMENTID` char(17) NOT NULL,
`ATTRIBUTEID` char(4) NOT NULL,
`VALUE` varchar(20) NOT NULL,
`COLLECTTIME` datetime NOT NULL
)
ENGINE=InnoDB (适用大部分引擎,可根据需要调整)
DEFAULT CHARSET=gbk(编码可根据需要修改)
PARTITION BY RANGE (to_days(COLLECTTIME))
(PARTITION pmin VALUES LESS THAN (to_days('2010-01-01')),
PARTITION p201001 VALUES LESS THAN (to_days('2010-02-01')) ,
PARTITION p201002 VALUES LESS THAN (to_days('2010-03-01')) ,
PARTITION p201003 VALUES LESS THAN (to_days('2010-04-01')) ,
PARTITION p201004 VALUES LESS THAN (to_days('2010-05-01')) ,
PARTITION p201005 VALUES LESS THAN (to_days('2010-06-01')) ,
PARTITION p201006 VALUES LESS THAN (to_days('2010-07-01')) ,
PARTITION p201007 VALUES LESS THAN (to_days('2010-08-01')) ,
PARTITION p201008 VALUES LESS THAN (to_days('2010-09-01')) ,
PARTITION p201009 VALUES LESS THAN (to_days('2010-10-01')) ,
PARTITION p201010 VALUES LESS THAN (to_days('2010-11-01')),
PARTITION p201011 VALUES LESS THAN (to_days('2010-12-01')),
PARTITION p201012 VALUES LESS THAN (to_days('2011-01-01')),
PARTITION p201101 VALUES LESS THAN (to_days('2011-02-01')),
PARTITION p201102 VALUES LESS THAN (to_days('2011-03-01')),
PARTITION p201103 VALUES LESS THAN (to_days('2011-04-01')),
PARTITION p201104 VALUES LESS THAN (to_days('2011-05-01')),
PARTITION p201105 VALUES LESS THAN (to_days('2011-06-01')),
PARTITION p201106 VALUES LESS THAN (to_days('2011-07-01')),
PARTITION p201107 VALUES LESS THAN (to_days('2011-08-01')),
PARTITION p201108 VALUES LESS THAN (to_days('2011-09-01')),
PARTITION p201109 VALUES LESS THAN (to_days('2011-10-01')),
PARTITION p201110 VALUES LESS THAN (to_days('2011-11-01')),
PARTITION p201111 VALUES LESS THAN (to_days('2011-12-01')),
PARTITION p201112 VALUES LESS THAN (to_days('2012-01-01')),
PARTITION pmax VALUES LESS THAN MAXVALUE );
为现有表创建分区
alter table 表名
PARTITION BY RANGE (to_days(COLLECTTIME))
(PARTITION pmin VALUES LESS THAN (to_days('2010-01-01')),
PARTITION p201001 VALUES LESS THAN (to_days('2010-02-01')) ,
PARTITION p201002 VALUES LESS THAN (to_days('2010-03-01')) ,
PARTITION p201003 VALUES LESS THAN (to_days('2010-04-01')) ,
PARTITION p201004 VALUES LESS THAN (to_days('2010-05-01')) ,
PARTITION p201005 VALUES LESS THAN (to_days('2010-06-01')) ,
PARTITION p201006 VALUES LESS THAN (to_days('2010-07-01')) ,
PARTITION p201007 VALUES LESS THAN (to_days('2010-08-01')) ,
PARTITION p201008 VALUES LESS THAN (to_days('2010-09-01')) ,
PARTITION p201009 VALUES LESS THAN (to_days('2010-10-01')) ,
PARTITION p201010 VALUES LESS THAN (to_days('2010-11-01')),
PARTITION p201011 VALUES LESS THAN (to_days('2010-12-01')),
PARTITION p201012 VALUES LESS THAN (to_days('2011-01-01')),
PARTITION p201101 VALUES LESS THAN (to_days('2011-02-01')),
PARTITION p201102 VALUES LESS THAN (to_days('2011-03-01')),
PARTITION p201103 VALUES LESS THAN (to_days('2011-04-01')),
PARTITION p201104 VALUES LESS THAN (to_days('2011-05-01')),
PARTITION p201105 VALUES LESS THAN (to_days('2011-06-01')),
PARTITION p201106 VALUES LESS THAN (to_days('2011-07-01')),
PARTITION p201107 VALUES LESS THAN (to_days('2011-08-01')),
PARTITION p201108 VALUES LESS THAN (to_days('2011-09-01')),
PARTITION p201109 VALUES LESS THAN (to_days('2011-10-01')),
PARTITION p201110 VALUES LESS THAN (to_days('2011-11-01')),
PARTITION p201111 VALUES LESS THAN (to_days('2011-12-01')),
PARTITION p201112 VALUES LESS THAN (to_days('2012-01-01')),
PARTITION pmax VALUES LESS THAN MAXVALUE );
如果表中已有数据,分区时会自动进行分区存储,不必担心数据丢失或者手动分类数据.
删除表中的指定分区
ALTER TABLE 表名 DROP PARTITION 分区名;
追加表分区
ALTER TABLE 表名 DROP PARTITION pmax;
ALTER TABLE 表名
ADD PARTITION (
PARTITION p201201 VALUES LESS THAN (to_days('2012-2-1')),
PARTITION pmax VALUES LESS THAN MAXVALUE);
查看标分区信息
SELECT
partition_name part,
partition_expression expr,
partition_description descr,
table_rows
FROM
INFORMATION_SCHEMA.partitions
WHERE
TABLE_SCHEMA = schema()
AND TABLE_NAME='表名';
查看查询语句涉及分区信息
explain partitions
select … from 表名 where …;
该操作只查看查询语句相关的分区信息,不会返回查询结果.

看完上述内容,你们对MySQL中怎么实现表分区功能有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


当前题目:MySQL中怎么实现表分区功能
转载来源:http://cdkjz.cn/article/ghepci.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220