mysql innodb单表分区实战

目的:为了了解mysql单表分区方法,特此作为学习笔记记录一下。

一。准备表,创建一个学生表,包含主键sid和名称sname字段

create table students(
sid int(5) primary key,
sname varchar(24)
);

二。准备数据

insert into students(sid,sname) values(10003,'tom');
insert into students(sid,sname) values(10005,'jerry');
insert into students(sid,sname) values(10006,'hengte');
insert into students(sid,sname) values(10007,'weilian');
insert into students(sid,sname) values(10000,'tom1');
insert into students(sid,sname) values(10001,'jerry2');
insert into students(sid,sname) values(10002,'hengte3');
insert into students(sid,sname) values(10004,'weilian4');

三。查询结果

select * from sutdents

四。建立分区,按照主键ID的值进行设定分区规则如下:

alter table students partition by range(sid)
(
partition p0 values less than (10001),
partition p1 values less than (10003),
partition p2 values less than (10005),
partition p3 values less than maxvalue
);

五。查询结果,可以看到查询结果分布到不同的分区里

select  * from students partition (p0);

select  * from students partition (p1);

select  * from students partition (p2);

select  * from students partition (p3);

六。验证新插入数据

insert into students(sid,sname) values(10011,'tom12');
insert into students(sid,sname) values(10012,'jerry13');
insert into students(sid,sname) values(10013,'hengte14');
insert into students(sid,sname) values(10014,'weilian15');
insert into students(sid,sname) values(10015,'tom116');
insert into students(sid,sname) values(10016,'jerry22');
insert into students(sid,sname) values(10017,'hengte32');
insert into students(sid,sname) values(10018,'weilian42');

七。再次查询分区数据,会看到新插入的数据按照分区规则划分到对应的分区里了

 

select  * from students partition (p0);

select  * from students partition (p1);

select  * from students partition (p2);

select  * from students partition (p3);

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值