1.schema.xml
[root@mysql1 conf]# cat schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="mycatdb" checkSQLschema="false" sqlMaxLimit="100">
<table name="my_test2" dataNode="dnmycatdb$1-9" rule="sharding-by-intfile-mycatdb-my_test2"></table>
<table name="my_test3" primaryKey="jobid" type="global" dataNode="dnmycatdb$1-9" ></table>
<table name="my_test4" dataNode="dnmycatdb$1-3" rule="mod-long" >
<childTable name="my_test4_child" primaryKey="orderdetail_id" joinKey="order_id" parentKey="order_id"/>
</table>
<table name="my_test5" dataNode="dnmycatdb$1-9" rule="auto-sharding-long"></table>
<table name="my_test6" dataNode="dnmycatdb$1-9" rule="sharding-by-murmur-id"></table>
</schema>
2.rule.xml
<tableRule name="sharding-by-murmur-id">
<rule>
<columns>id</columns>
<algorithm>murmur-id</algorithm>
</rule>
</tableRule>
<function name="murmur-id" class="io.mycat.route.function.PartitionByMurmurHash">
<property name="seed">0</property>
<property name="type">0</property>
<property name="count">9</property>
<property name="virtualBucketTimes">160</property>
<property name="bucketMapPath">/mysql/app/mycat/logs/bucketMapPath-murmur-id</property>
</function>
3.准备表
create table my_test6(id int,name varchar(20));
insert into my_test6(id ,name)values(20000000,'xsq1');
insert into my_test6(id ,name)values(20000001,'xsq2');
insert into my_test6(id ,name)values(20005001,'xsq3');
insert into my_test6(id ,name)values(20005002,'xsq4');
insert into my_test6(id ,name)values(20010001,'xsq5');
insert into my_test6(id ,name)values(20010002,'xsq6');
insert into my_test6(id ,name)values(20015001,'xsq7');
insert into my_test6(id ,name)values(20015002,'xsq8');
insert into my_test6(id ,name)values(20020001,'xsq9');
insert into my_test6(id ,name)values(20020002,'xsq10');
insert into my_test6(id ,name)values(20025001,'xsq11');
insert into my_test6(id ,name)values(20025002,'xsq12');
insert into my_test6(id ,name)values(20030001,'xsq13');
insert into my_test6(id ,name)values(20030002,'xsq14');
insert into my_test6(id ,name)values(20035001,'xsq15');
insert into my_test6(id ,name)values(20035002,'xsq16');
insert into my_test6(id ,name)values(20040001,'xsq17');
insert into my_test6(id ,name)values(20040002,'xsq18');
"sspu@192.168.1.11">select * from my_test6;
+----------+-------+
| id | name |
+----------+-------+
| 20020002 | xsq10 |
| 20005001 | xsq3 |
| 20035001 | xsq15 |
| 20015001 | xsq7 |
| 20030001 | xsq13 |
| 20030002 | xsq14 |
| 20015002 | xsq8 |
| 20025002 | xsq12 |
| 20040001 | xsq17 |
| 20000000 | xsq1 |
| 20000001 | xsq2 |
| 20005002 | xsq4 |
| 20010001 | xsq5 |
| 20010002 | xsq6 |
| 20035002 | xsq16 |
| 20025001 | xsq11 |
| 20040002 | xsq18 |
| 20020001 | xsq9 |
+----------+-------+
18 rows in set (0.02 sec)
4.查看数据的分布。
"root@localhost">select * from sspudb1.my_test6;
+----------+-------+
| id | name |
+----------+-------+
| 20005001 | xsq3 |
| 20035001 | xsq15 |
+----------+-------+
2 rows in set (0.00 sec)
"root@localhost">select * from sspudb2.my_test6;
+----------+-------+
| id | name |
+----------+-------+
| 20015001 | xsq7 |
| 20030001 | xsq13 |
| 20030002 | xsq14 |
+----------+-------+
3 rows in set (0.00 sec)
"root@localhost">select * from sspudb3.my_test6;
+----------+-------+
| id | name |
+----------+-------+
| 20000000 | xsq1 |
| 20000001 | xsq2 |
| 20005002 | xsq4 |
| 20010001 | xsq5 |
| 20010002 | xsq6 |
| 20035002 | xsq16 |
+----------+-------+
6 rows in set (0.00 sec)
"root@localhost">select * from sspudb4.my_test6;
Empty set (0.00 sec)
"root@localhost">select * from sspudb5.my_test6;
+----------+-------+
| id | name |
+----------+-------+
| 20015002 | xsq8 |
| 20025002 | xsq12 |
| 20040001 | xsq17 |
+----------+-------+
3 rows in set (0.00 sec)
"root@localhost">select * from sspudb6.my_test6;
+----------+-------+
| id | name |
+----------+-------+
| 20020002 | xsq10 |
+----------+-------+
1 row in set (0.00 sec)
"root@localhost">select * from sspudb7.my_test6;
+----------+------+
| id | name |
+----------+------+
| 20020001 | xsq9 |
+----------+------+
1 row in set (0.00 sec)
"root@localhost">select * from sspudb8.my_test6;
+----------+-------+
| id | name |
+----------+-------+
| 20025001 | xsq11 |
| 20040002 | xsq18 |
+----------+-------+
2 rows in set (0.00 sec)
"root@localhost">select * from sspudb9.my_test6;
Empty set (0.00 sec)
5.总结
水平分库,一致性HASH分库,数据是不均匀分布的。