时间:2021-07-01 10:21:17 帮助过:16人阅读
对Select操作,mycat会随机现在一个节点输出结果内容;
对Insert-Update-Delete操作,Mycat会操作所有节点
mycat er 表
mycat节点 192.168.239.140
修改schema.xml
1 <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0" 2 writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> 3 <heartbeat>select user()</heartbeat> 4 5 <writeHost host="hostM1" url="localhost:3306" user="scos" 6 password="scos"> 7 8 <readHost host="hostS2" url="localhost:3306" user="scos" password="scos" /> 9 </writeHost> 10 11 </dataHost>
./mycat console
customer表与子表orders和order_items的关系如下
1 <table name="customer" primaryKey="ID" dataNode="dn1,dn2" 2 rule="sharding-by-intfile"> 3 <childTable name="orders" primaryKey="ID" joinKey="customer_id" 4 parentKey="id"> 5 <childTable name="order_items" joinKey="order_id" 6 parentKey="id" /> 7 </childTable> 8 <childTable name="customer_addr" primaryKey="ID" joinKey="customer_id" 9 parentKey="id" /> 10 </table>
查看rule.xml
1 <tableRule name="sharding-by-intfile"> 2 <rule> 3 <columns>sharding_id</columns> 4 <algorithm>hash-int</algorithm> 5 </rule> 6 </tableRule>
mysql -u root -p -h192.168.239.140 -P8066
1 创建表 2 create table customer (id int PRIMARY KEY,name VARCHAR(10),sharding_id INT); 3 create table orders (id int PRIMARY KEY,name VARCHAR(10),customer_id INT); 4 create table order_items (id int PRIMARY KEY,order_id int ); 5 6 7 INSERT into customer (id,name,sharding_id) values (1,‘xiaoming‘,10000); 8 explain INSERT into customer (id,name,sharding_id) values (1,‘xiaoming‘,10000); 9 10 data_node dn1 11 12 insert into orders (id,name,customer_id) VALUES (1,‘goods‘,1); 13 14 INSERT into order_items (id,order_id) VALUES(1,1);
mysql -uroot -proot 登陆
1 use db1 2 show tables; 3 4 customer employee orders
验证
1 INSERT into customer (id,name,sharding_id) values (2,‘xiaoming‘,10000); 2 3 explain INSERT into customer (id,name,sharding_id) values (2,‘xiaoming‘,10000); 4 5 data_node dn2
另一种方式,客户端组件分片
sharding JDBC
完
mysql05
标签:ack beat 可靠性 高性能 ash OLE prim algorithm 水平