MySQL中使用表分区(table的partition)

建表语句以下:mysql

create table comment_partition(
  id int not null auto_increment,
  commenterIpv4 char(30),
  blog int not null,
  content text,
  commentDate varchar(255),
  primary key(id,blog))
partition by linear hash(blog)
partitions 10;

注意:用blog字段来分区,它必须是主键的一部分。sql

以下为插入一些数据:code

INSERT INTO `comment_partition` VALUES (1,'127.0.0.1',2,'66666666666666666','2016-06-07 11-19'),(2,'127.0.0.1',2,'比较受用,谢谢博主。。。我也写了份c3p0的使用实例,在个人OSChina上,欢迎你们阅读并提出建议。。。。','2016-06-07 11-56'),(3,'127.0.0.1',2,'谢博主分享。。。','2016-06-07 12-00'),(4,'127.0.0.1',2,'多谢博主分享。。。。','2016-06-07 12-29'),(5,'127.0.0.1',3,'看了博主的分享后,终于解决了个人问题了。。。。','2016-06-07 12-30'),(6,'127.0.0.1',7,'6666666666666  3333333333333333333','2016-06-07 21-07'),(7,'127.0.0.1',7,'22223333333','2016-06-07 21-08'),(8,'127.0.0.1',7,'感谢博主分享。。。多谢了。。。','2016-06-07 21-08'),(9,'127.0.0.1',2,'233333332222222222222233333333333333','2016-06-07 21-33'),(10,'127.0.0.1',9,'6666666666666666','2016-06-07 21-35'),(11,'127.0.0.1',7,'多谢博主分享','2016-06-07 21-36'),(12,'127.0.0.1',8,'这种用apt-get install方式安装的话不少文件都找不到了。。。。','2016-06-07 21-36'),(13,'127.0.0.1',4,'看了看了','2016-06-08 19-38');blog

 

插入数据后mysql会根据不一样的blog的值将记录放到不一样的区中,以下为查看咱们查询时mysql从哪一个分区查询咱们的数据(在mysql的命令窗口中输入以下命令):rem


explain partitions select id,blog from comment_partition where blog=6;get

 

结果以下图(从p6分区中查询到):hash

相关文章
相关标签/搜索