[root@db01 conf]# cp schema.xml schema.xml.mha [root@db01 conf]# 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="user" dataNode="sh1"/> <table name="order_t" dataNode="sh2"/> </schema> <dataNode name="sh1" dataHost="guo1" database= "taobao" /> <dataNode name="sh2" dataHost="guo2" database= "taobao" /> <dataHost name="guo1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1"> <heartbeat>select user()</heartbeat> <writeHost host="db1" url="10.0.0.200:3307" user="root" password="123"> <readHost host="db2" url="10.0.0.200:3309" user="root" password="123" /> </writeHost> <writeHost host="db3" url="10.0.0.201:3307" user="root" password="123"> <readHost host="db4" url="10.0.0.201:3309" user="root" password="123" /> </writeHost> </dataHost> <dataHost name="guo2" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1"> <heartbeat>select user()</heartbeat> <writeHost host="db1" url="10.0.0.200:3308" user="root" password="123"> <readHost host="db2" url="10.0.0.200:3310" user="root" password="123" /> </writeHost> <writeHost host="db3" url="10.0.0.201:3308" user="root" password="123"> <readHost host="db4" url="10.0.0.201:3310" user="root" password="123" /> </writeHost> </dataHost>
创建测试库和表(db01)
mysql -S /data/3307/mysql.sock -e "create database taobao charset utf8;" mysql -S /data/3308/mysql.sock -e "create database taobao charset utf8;" mysql -S /data/3307/mysql.sock -e "use taobao;create table user(id int,name varchar(20))"; mysql -S /data/3308/mysql.sock -e "use taobao;create table order_t(id int,name varchar(20))"
查看效果
[root@db01 conf]# mycat restart [root@db01 conf]# mysql -uroot -p123456 -h 127.0.0.1 -P 8066 mysql> use TESTDB mysql> show tables; +------------------+ | Tables_in_taobao | +------------------+ | order_t | | user | +------------------+