mycat one群:106088787。
说明:根据分片字段取模。
一、conf/schema.xml文件
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
<table name="partition_by_mod" primaryKey="id" dataNode="dn$0-2"
rule="partition-by-mod" />
</schema>
<dataNode name="dn0" dataHost="dh-1" database="db0"/>
<dataNode name="dn1" dataHost="dh-1" database="db1"/>
<dataNode name="dn2" dataHost="dh-1" database="db2"/>
<dataHost name="dh-1" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="hostM1" url="localhost:3306" user="root"
password="123456">
</writeHost>
</dataHost>
</mycat:schema>
二、conf/rule.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:rule SYSTEM "rule.dtd">
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="partition-by-mod">
<rule>
<columns>id</columns>
<algorithm>partition-by-mod</algorithm>
</rule>
</tableRule>
<function name="partition-by-mod"
class="io.mycat.route.function.PartitionByMod">
<property name="count">3</property>
</function>
</mycat:rule>
三、规则文件信息
无
四、测试用到的sql
=============按照id字段 取模================
CREATE TABLE partition_by_mod (id int(10) null,`db_nm` varchar(20) NULL);
INSERT INTO `partition_by_mod` (id,db_nm) VALUES (1, database());
INSERT INTO `partition_by_mod` (id,db_nm) VALUES (2, database());
INSERT INTO `partition_by_mod` (id,db_nm) VALUES (3, database());
INSERT INTO `partition_by_mod` (id,db_nm) VALUES (10, database());
select * from partition_by_mod;
五、注意事项
1、分片的个数多少合适,需要提前规划好
2、如果运行了的系统再扩展,数据迁移解决
六、参数说明
count::分片个数