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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| mv schema.xml schema.xml.1 vim 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" dataNode="sh1"> <table name="t3" dataNode="sh1,sh2" rule="auto-sharding-long" /> </schema> <dataNode name="sh1" dataHost="wufei1" database= "taobao" /> <dataNode name="sh2" dataHost="wufei2" database= "taobao" /> <dataHost name="wufei1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1"> <heartbeat>select user()</heartbeat> <writeHost host="db1" url="10.0.1.51:3307" user="root" password="123"> <readHost host="db2" url="10.0.1.51:3309" user="root" password="123" /> </writeHost> <writeHost host="db3" url="10.0.1.52:3307" user="root" password="123"> <readHost host="db4" url="10.0.1.52:3309" user="root" password="123" /> </writeHost> </dataHost> <dataHost name="wufei2" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1"> <heartbeat>select user()</heartbeat> <writeHost host="db1" url="10.0.1.51:3308" user="root" password="123"> <readHost host="db2" url="10.0.1.51:3310" user="root" password="123" /> </writeHost> <writeHost host="db3" url="10.0.1.52:3308" user="root" password="123"> <readHost host="db4" url="10.0.1.52:3310" user="root" password="123" /> </writeHost> </dataHost> </mycat:schema>
vim rule.xml
<tableRule name="auto-sharding-long"> <rule> <columns>id</columns> <algorithm>rang-long</algorithm> </rule>
<function name="rang-long" class="io.mycat.route.function.AutoPartitionByLong"> <property name="mapFile">autopartition-long.txt</property> </function>
vim autopartition-long.txt 0-10=0 10-20=1
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);"
mycat restart mysql -uroot -p123456 -h 127.0.0.1 -P 8066 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');
|