Mycat 垂直分表

垂直分表

cp schema.xml{,.ori}
vim schema.xml
<!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="test1" database= "taobao" />
	<dataNode name="sh2" dataHost="test2" database= "taobao" />         
        <dataHost name="test1" 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.12:3307" user="root" password="123">
                        <readHost host="db2" url="10.0.0.12:3309" user="root" password="123" /> 
        </writeHost> 
		 <writeHost host="db3" url="10.0.0.13:3307" user="root" password="123">
                        <readHost host="db4" url="10.0.0.13:3309" user="root" password="123" /> 
        </writeHost> 
        </dataHost>
	<dataHost name="test2" 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.12:3308" user="root" password="123">
                        <readHost host="db2" url="10.0.0.12:33010" user="root" password="123" /> 
        </writeHost> 
                 <writeHost host="db3" url="10.0.0.13:3308" user="root" password="123">
                        <readHost host="db4" url="10.0.0.13:33010" user="root" password="123" /> 
        </writeHost> 
        </dataHost>   
</mycat:schema>

创建测试库和表

[root@db01 conf]# mysql -S /data/3307/mysql.sock -e "create database taobao charset utf8;"
[root@db01 conf]# mysql -S /data/3308/mysql.sock -e "create database taobao charset utf8;"
[root@db01 conf]# mysql -S /data/3307/mysql.sock -e "use taobao;create table user(id int,name varchar(20))";
[root@db01 conf]# mysql -S /data/3308/mysql.sock -e "use taobao;create table order_t(id int,name varchar(20))";

重启mycat :

mycat restart

测试功能

[root@db01 conf]# mysql -uroot -p123456 -h 10.0.0.10 -P 8066
mysql> use TESTDB
mysql> show tables;
+------------------+
| Tables_in_taobao |
+------------------+
| order_t          |
| user             |
+------------------+
mysql> insert into user(id ,name ) values(1,'a'),(2,'b');
mysql> commit;

mysql> insert into order_t(id ,name ) values(1,'a'),(2,'b');
mysql> commit;

[root@db01 ~]# mysql -S /data/3307/mysql.sock -e "show tables from taobao;"
+------------------+
| Tables_in_taobao |
+------------------+
| user             |
+------------------+
[root@db01 ~]# mysql -S /data/3308/mysql.sock -e "show tables from taobao;"
+------------------+
| Tables_in_taobao |
+------------------+
| order_t          |
+------------------+
[root@db01 ~]# 
posted @ 2020-07-23 11:01  国际一级退堂鼓鼓手  阅读(270)  评论(0编辑  收藏  举报