[root@db02 /application/mycat/conf]# vim autopartition-long.txt 1 # range start-end ,data node index 2 # K=1000,M=10000. 3 0-500M=0 4 500M-1000M=1 5 1000M-1500M=2 开始-结束=分片编号 例:1000w行-1500w行放在了第三个数据节点(编号为2)上了
[root@db02 /application/mycat/conf]# vim autopartition-long.txt 0-10=0 11-20=1 //这里我门设定步长为10进行范围分片
创建测试表(任意机器执行db1或db2): mysql -S /data/3307/mysql.sock -e "use taobao;create table t3 (id int not null primary key auto_increment,name varchar(20) not null);" mysql -S /data/3308/mysql.sock -e "use taobao;create table t3 (id int not null primary key auto_increment,name varchar(20) not null);"
mysql -uroot -p123456 -h10.0.0.52 -P8066 mysql> use TESTDB; mysql> show tables; +------------------+ | Tables_in_taobao | +------------------+ | t3 | | user | +------------------+ 2 rows inset (0.00 sec)
insert into t3(id,name) values(1,'a'); insert into t3(id,name) values(2,'b'); insert into t3(id,name) values(3,'c'); insert into t3(id,name) values(4,'d'); insert into t3(id,name) values(11,'aa'); insert into t3(id,name) values(12,'bb'); insert into t3(id,name) values(13,'cc'); insert into t3(id,name) values(14,'dd');
104 <function name="mod-long" class="io.mycat.route.function.PartitionByMod"> 105 <!-- how many data nodes --> 106 <property name="count">2</property> //节点数量 107 </function>
创建测试表(任意机器执行db1或db2): mysql -S /data/3307/mysql.sock -e "use taobao;create table t4 (id int not null primary key auto_increment,name varchar(20) not null);" mysql -S /data/3308/mysql.sock -e "use taobao;create table t4 (id int not null primary key auto_increment,name varchar(20) not null);"
重启mycat (db02)
mycat restart
db02上添加测试数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
mysql -uroot -p123456 -h10.0.0.52 -P8066 use TESTDB insert into t4(id,name) values(1,'a'); insert into t4(id,name) values(2,'b'); insert into t4(id,name) values(3,'c'); insert into t4(id,name) values(4,'d');
创建测试表(任意机器执行db1或db2): mysql -S /data/3307/mysql.sock -e "use taobao;create table t5 (id int not null primary key auto_increment,name varchar(20) not null);" mysql -S /data/3308/mysql.sock -e "use taobao;create table t5 (id int not null primary key auto_increment,name varchar(20) not null);"
重启mycat mycat restart
db02上添加测试数据
1 2 3 4 5 6 7
mysql -uroot -p123456 -h10.0.0.52 -P8066 use TESTDB insert into t5(id,name) values(1,'bj'); insert into t5(id,name) values(2,'sh'); insert into t5(id,name) values(3,'bj'); insert into t5(id,name) values(4,'sh'); insert into t5(id,name) values(5,'tj');
测试表准备: mysql -S /data/3307/mysql.sock -e "use taobao;create table t_area (id int not null primary key auto_increment,name varchar(20) not null);" mysql -S /data/3308/mysql.sock -e "use taobao;create table t_area (id int not null primary key auto_increment,name varchar(20) not null);"
重启mycat (db02)
mycat restart
插入测试数据
1 2 3 4 5 6
mysql -uroot -p123456 -h10.0.0.52 -P8066 use TESTDB insert into t_area(id,name) values(1,'a'); insert into t_area(id,name) values(2,'b'); insert into t_area(id,name) values(3,'c'); insert into t_area(id,name) values(4,'d');
检查后端数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
//所以节点上都存在相同的全局表,而且数据一致 [root@db01 ~]# mysql -S /data/3307/mysql.sock -e "use taobao;select * from t_area;"+----+------+ | id | name | +----+------+ | 1 | a | | 2 | b | | 3 | c | | 4 | d | +----+------+ [root@db01 ~]# mysql -S /data/3308/mysql.sock -e "use taobao;select * from t_area;" +----+------+ | id | name | +----+------+ | 1 | a | | 2 | b | | 3 | c | | 4 | d | +----+------+
E-R分片
说明:类似于全局表,但比全局表性能高。 例如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
A join B //将A 表和B表中相关连的条件,同时分片放入同一个节点中 为了防止跨分片join,可以使用E-R模式 A join B on a.xx=b.yy join C on A.id=C.id