您好,登錄后才能下訂單哦!
項目環境:
192.168.8.30 mycat
192.168.8.31 node1
192.168.8.32 node2
192.168.8.33 node3
三個節點MySQL均為單實例
一、配置schema.xml
<?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <schema name="mycatdb" checkSQLschema="false" sqlMaxLimit="100"> <table name="user02" primaryKey="id" type="global" dataNode="dn$1-35" /> <table name="user01" dataNode="dn$1-35" rule="sharding-by-intfile-mycatdb-kk_user" /> </schema> <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743" /> --> <dataNode name="dn1" dataHost="node1" database="testdb01" /> <dataNode name="dn2" dataHost="node1" database="testdb02" /> <dataNode name="dn3" dataHost="node1" database="testdb03" /> <dataNode name="dn4" dataHost="node1" database="testdb04" /> <dataNode name="dn5" dataHost="node1" database="testdb05" /> <dataNode name="dn6" dataHost="node1" database="testdb06" /> <dataNode name="dn7" dataHost="node1" database="testdb07" /> <dataNode name="dn8" dataHost="node1" database="testdb08" /> <dataNode name="dn9" dataHost="node1" database="testdb09" /> <dataNode name="dn10" dataHost="node1" database="testdb10" /> <dataNode name="dn11" dataHost="node1" database="testdb11" /> <dataNode name="dn12" dataHost="node1" database="testdb12" /> <dataNode name="dn13" dataHost="node2" database="testdb13" /> <dataNode name="dn14" dataHost="node2" database="testdb14" /> <dataNode name="dn15" dataHost="node2" database="testdb15" /> <dataNode name="dn16" dataHost="node2" database="testdb16" /> <dataNode name="dn17" dataHost="node2" database="testdb17" /> <dataNode name="dn18" dataHost="node2" database="testdb18" /> <dataNode name="dn19" dataHost="node2" database="testdb19" /> <dataNode name="dn20" dataHost="node2" database="testdb20" /> <dataNode name="dn21" dataHost="node2" database="testdb21" /> <dataNode name="dn22" dataHost="node2" database="testdb22" /> <dataNode name="dn23" dataHost="node2" database="testdb23" /> <dataNode name="dn24" dataHost="node2" database="testdb24" /> <dataNode name="dn25" dataHost="node3" database="testdb25" /> <dataNode name="dn26" dataHost="node3" database="testdb26" /> <dataNode name="dn27" dataHost="node3" database="testdb27" /> <dataNode name="dn28" dataHost="node3" database="testdb28" /> <dataNode name="dn29" dataHost="node3" database="testdb29" /> <dataNode name="dn30" dataHost="node3" database="testdb30" /> <dataNode name="dn31" dataHost="node3" database="testdb31" /> <dataNode name="dn32" dataHost="node3" database="testdb32" /> <dataNode name="dn33" dataHost="node3" database="testdb33" /> <dataNode name="dn34" dataHost="node3" database="testdb34" /> <dataNode name="dn35" dataHost="node3" database="testdb35" /> <!--<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="node1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <!-- can have multi write hosts --> <writeHost host="192.168.8.31" url="192.168.8.31:3306" user="root" password="mysql"></writeHost> </dataHost> <dataHost name="node2" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <!-- can have multi write hosts --> <writeHost host="192.168.8.32" url="192.168.8.32:3306" user="root" password="mysql"></writeHost> </dataHost> <dataHost name="node3" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <!-- can have multi write hosts --> <writeHost host="192.168.8.33" url="192.168.8.33:3306" user="root" password="mysql"></writeHost> </dataHost> </mycat:schema>
二、配置server.xml
<user name="root" defaultAccount="true"> <property name="password">mysql</property> <property name="schemas">mycatdb</property> </user>
三、創建測試庫
node1
create database testdb01; create database testdb02; create database testdb03;
node2
create database testdb13; create database testdb14; create database testdb15;
node3
create database testdb25; create database testdb26; create database testdb27;
四、啟動mycat
/usr/local/mycat/bin/mycat start
查看mycat日志
STATUS | wrapper | 2018/11/22 10:58:17 | --> Wrapper Started as Daemon STATUS | wrapper | 2018/11/22 10:58:18 | Launching a JVM... INFO | jvm 1 | 2018/11/22 10:58:18 | OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=64M; support was removed in 8.0 INFO | jvm 1 | 2018/11/22 10:58:20 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org INFO | jvm 1 | 2018/11/22 10:58:20 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved. INFO | jvm 1 | 2018/11/22 10:58:20 | INFO | jvm 1 | 2018/11/22 10:58:24 | MyCAT Server startup successfully. see logs in logs/mycat.log
五、登錄MySQL查看全局表
mysql -uroot -pmysql -P8066 -h292.168.8.30
mysql> use mycatdb Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +-------------------+ | Tables in mycatdb | +-------------------+ | user01 | | user02 | +-------------------+ 2 rows in set (0.01 sec) mysql> drop table user02; ERROR 1105 (HY000): Unknown table 'testdb11.user02' mysql> select * from user02; ERROR 1146 (HY000): Table 'testdb01.user02' doesn't exist mysql> drop table if exists user02; Query OK, 0 rows affected, 1 warning (0.40 sec
建表user02并插入三條記錄
mysql> create table user02( -> id INT(10) NOT NULL AUTO_INCREMENT, -> name varchar(30), -> PRIMARY KEY ( id ) -> ); Query OK, 0 rows affected (1.74 sec) mysql> insert into user02(name) values('steven'); Query OK, 1 row affected (0.29 sec) mysql> insert into user02(name) values('steven'); Query OK, 1 row affected (0.33 sec) mysql> insert into user02(name) values('steven'); Query OK, 1 row affected (0.31 sec)
六、數據驗證
node1
mysql> select * from testdb01.user02; +----+--------+ | id | name | +----+--------+ | 1 | steven | | 2 | steven | | 3 | steven | +----+--------+ 3 rows in set (0.00 sec) mysql> select * from testdb05.user02; +----+--------+ | id | name | +----+--------+ | 1 | steven | | 2 | steven | | 3 | steven | +----+--------+ 3 rows in set (0.01 sec) mysql> select * from testdb12.user02; +----+--------+ | id | name | +----+--------+ | 1 | steven | | 2 | steven | | 3 | steven | +----+--------+ 3 rows in set (0.00 sec)
node2
mysql> select * from testdb16.user02; +----+--------+ | id | name | +----+--------+ | 1 | steven | | 2 | steven | | 3 | steven | +----+--------+ 3 rows in set (0.00 sec) mysql> select * from testdb19.user02; +----+--------+ | id | name | +----+--------+ | 1 | steven | | 2 | steven | | 3 | steven | +----+--------+ 3 rows in set (0.00 sec) mysql> select * from testdb22.user02; +----+--------+ | id | name | +----+--------+ | 1 | steven | | 2 | steven | | 3 | steven | +----+--------+ 3 rows in set (0.00 sec)
node3
mysql> select * from testdb25.user02; +----+--------+ | id | name | +----+--------+ | 1 | steven | | 2 | steven | | 3 | steven | +----+--------+ 3 rows in set (0.00 sec) mysql> select * from testdb30.user02; +----+--------+ | id | name | +----+--------+ | 1 | steven | | 2 | steven | | 3 | steven | +----+--------+ 3 rows in set (0.00 sec) mysql> select * from testdb33.user02; +----+--------+ | id | name | +----+--------+ | 1 | steven | | 2 | steven | | 3 | steven | +----+--------+
可以看到每個node的每個database存的數據都一模一樣,全局表驗證完畢。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。