场景一:node
1.一个全局表 t_testmysql
a. 经过mycat 操做数据 insert 、delete 数据,则对应的2个datanode中的数据 都会被删除算法
b. 2个datanode中的数据不一样时 ,不会相互同步。sql
注:貌似从官方描述上来讲 ,是会自动同步的。测试
摘自:Mycat 官方开发指南 V1.6.0中ui
2.测试分片规则url
2.1 分片枚举spa
<?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="employee" primaryKey="ID" dataNode="dn1,dn2" rule="sharding-by-intfile" /> </schema> <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743" /> --> <dataNode name="dn1" dataHost="localhost1" database="db1" /> <dataNode name="dn2" dataHost="localhost1" database="db2" /> <dataNode name="dn3" dataHost="localhost1" database="db3" /> <!--<dataNode name="dn4" dataHost="sequoiadb1" database="SAMPLE" /> <dataNode name="jdbc_dn1" dataHost="jdbchost" database="db1" /> <dataNode name="jdbc_dn2" dataHost="jdbchost" database="db2" /> <dataNode name="jdbc_dn3" dataHost="jdbchost" database="db3" /> --> <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <!-- can have multi write hosts --> <writeHost host="hostM1" url="localhost:3307" user="root" password="123456"> <!-- can have multi read hosts --> <readHost host="hostS2" url="localhost:3307" user="root" password="123456" /> </writeHost> </dataHost> </mycat:schema>
create table employee (id int not null primary key,name varchar(100),sharding_id int not null);code
insert into employee(id,name,sharding_id) values(1,'hutuchong',10000);xml
insert into employee(id,name,sharding_id) values(2,'zhanghui',10010);
这两条数据会分别查到不一样的分片上,由于 表配置了这个rule规则
rule="sharding-by-intfile" ,在rule.xml中配置了算法,对应的文件以下
这个意思是 当值10000时存 index为0的分片(第一个分片 dn1)
2.2 全局表
<?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <!--aps_acct start--> <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100"> <table name="t_test" type="global" dataNode="aps_acct_node1,aps_acct_node2" /> </schema> <dataNode name="aps_acct_node1" dataHost="aps_acct_host1" database="aps_acct" /> <dataNode name="aps_acct_node2" dataHost="aps_acct_host2" database="aps_acct" /> <dataHost name="aps_acct_host1" 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:3307" user="root" password="123456"> <readHost host="hostS2" url="localhost:3307" user="root" password="123456" /> </writeHost> </dataHost> <dataHost name="aps_acct_host2" 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:3308" user="root" password="123456"> <readHost host="hostS2" url="localhost:3308" user="root" password="123456" /> </writeHost> </dataHost> <!--aps_acct start--> </mycat:schema>
参见1
2.3 天然月
<?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <!--aps_acct start--> <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100"> <table name="t_order" dataNode="aps_acct_node1,aps_acct_node2" rule="sharding-by-month" /> </schema> <dataNode name="aps_acct_node1" dataHost="aps_acct_host1" database="aps_acct" /> <dataNode name="aps_acct_node2" dataHost="aps_acct_host2" database="aps_acct" /> <dataHost name="aps_acct_host1" 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:3307" user="root" password="123456"> <readHost host="hostS2" url="localhost:3307" user="root" password="123456" /> </writeHost> </dataHost> <dataHost name="aps_acct_host2" 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:3308" user="root" password="123456"> <readHost host="hostS2" url="localhost:3308" user="root" password="123456" /> </writeHost> </dataHost> <!--aps_acct start--> </mycat:schema>
CREATE TABLE t_order(id INT NOT NULL PRIMARY KEY,create_time DATETIME NOT NULL);
INSERT INTO t_order(id,create_time) VALUES(1,'2015-01-01')
INSERT INTO t_order(id,create_time) VALUES(2,'2015-02-01')
请检查文件 rule.xml
须要插入2015年开始的数据
这样2条数据就分别进入到 对应的datanode, 因为每一年有12个月,全部累计须要对应不少datanode
1,2,3,4...,24,....48....