1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
dn1: #连接数据库 /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql1.sock -Dsysbench #执行建表操作 CREATE TABLE `users2` ( `id` int(11) NOT NULL, `name` varchar(50) NOT NULL DEFAULT '', `indate` datetime NOT NULL DEFAULT '1910-01-01 00:00:00', PRIMARY KEY (`id`) ) ENGINE=InnoDB; dn2: #连接数据库 /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql2.sock -Dsysbench #执行建表操作 CREATE TABLE `users2` ( `id` int(11) NOT NULL, `name` varchar(50) NOT NULL DEFAULT '', `indate` datetime NOT NULL DEFAULT '1910-01-01 00:00:00', PRIMARY KEY (`id`) ) ENGINE=InnoDB; dn3: #连接数据库 /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql3.sock -Dsysbench #执行建表操作 CREATE TABLE `users2` ( `id` int(11) NOT NULL, `name` varchar(50) NOT NULL DEFAULT '', `indate` datetime NOT NULL DEFAULT '1910-01-01 00:00:00', PRIMARY KEY (`id`) ) ENGINE=InnoDB; |
1
|
vim /usr/local/mycat/conf/schema.xml
|
1
|
<table name="users2" primaryKey="id" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" autoIncrement="true" fetchStoreNodeByJdbc="true"> </table> |
1
|
vim /usr/local/mycat/conf/autopartition-long.txt
|
1 2 3 4 5 |
# range start-end ,data node index # K=1000,M=10000. 1-10000=0 10001-20000=1 20001-30000=2 |
id为1-10000的行数据保存到dn1分片里,id为10001-20000的行数据保存到dn2分片里,id为20001-30000的行数据保存到dn3分片里。
1 2 3 |
mycat stop mycat start mycat status |
1
|
vim /home/insert-autopartition.sh
|
1 2 3 4 5 |
#!/bin/bash for i in {1..30000} do /usr/local/mysql/bin/mysql -uroot -p1234567 -P8066 -h127.0.0.1 --default_auth=mysql_native_password -Dsysbench -e "insert into users2(id,name) values($i,'ccc')" done |
1
|
sh /home/insert-autopartition.sh
|
1 2 |
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql1.sock -Dsysbench -e "select count(*) from users2" /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql1.sock -Dsysbench -e "select max(id) from users2" |
1 2 |
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql2.sock -Dsysbench -e "select count(*) from users2" /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql2.sock -Dsysbench -e "select max(id) from users2" |
1 2 |
/usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql3.sock -Dsysbench -e "select count(*) from users2" /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql3.sock -Dsysbench -e "select max(id) from users2" |
30000条数据按照autopartition-long.txt文件定制的规则分布在指定的数据节点上。