Mysql 分区

Mysql5.1支持分区;

创建表时创建分区(分区有rang分区、list分区、hash分区、key分区和子分区,具体详见:http://blog.51yip.com/mysql/1013.html

create table testA (id int not null)
engine=innodb partition by range(id)
(partition p0 values less than (10),
partition p1 values less than (MAXVALUE));

查询某张表的分区信息(mysql必须支持分区,否则information库里不存在partition表)

select partition_name from INFORMATION_SCHEMA.PARTITIONS where TABLE_SCHEMA=数据库名称 and table_name='testA' 

删除分区

alter table testA drop partition p1;

修改分区

alter table testA add partition(partition p2 values less than (20));

注:如果添加了partition p1 values less than MAXVALUE后,则无法添加分区,MySQL要求MAXVAULE必须是最后一个分区。

查询出数据所在分区

explain partitions select * from temp where 分区列=xxx
posted @ 2014-03-05 23:22  世间安得两全法  阅读(193)  评论(0)    收藏  举报