项目环境:
192.168.8.30 mycat
192.168.8.31 node1
192.168.8.32 node2
192.168.8.33 node3
三个节点MySQL均为单实例
一、创建测试数据
node1
create database testdb1; create table testdb1.t01(name1 varchar(40),name2 varchar(40),name3 varchar(40)); insert into testdb1.t01 values(@@hostname,@@hostname,@@hostname); create database testdb2; create table testdb2.t02(name1 varchar(40),name2 varchar(40),name3 varchar(40)); insert into testdb2.t02 values(@@hostname,@@hostname,@@hostname); create database testdb3; create table testdb3.t03(name1 varchar(40),name2 varchar(40),name3 varchar(40)); insert into testdb3.t03 values(@@hostname,@@hostname,@@hostname);
node2
create database testdb4; create table testdb4.t04(name1 varchar(40),name2 varchar(40),name3 varchar(40)); insert into testdb4.t04 values(@@hostname,@@hostname,@@hostname); create database testdb5; create table testdb5.t05(name1 varchar(40),name2 varchar(40),name3 varchar(40)); insert into testdb5.t05 values(@@hostname,@@hostname,@@hostname); create database testdb6; create table testdb6.t06(name1 varchar(40),name2 varchar(40),name3 varchar(40)); insert into testdb6.t06 values(@@hostname,@@hostname,@@hostname);
node3
create database testdb7; create table testdb7.t07(name1 varchar(40),name2 varchar(40),name3 varchar(40)); insert into testdb7.t07 values(@@hostname,@@hostname,@@hostname); create database testdb8; create table testdb8.t08(name1 varchar(40),name2 varchar(40),name3 varchar(40)); insert into testdb8.t08 values(@@hostname,@@hostname,@@hostname); create database testdb9; create table testdb9.t09(name1 varchar(40),name2 varchar(40),name3 varchar(40)); insert into testdb9.t09 values(@@hostname,@@hostname,@@hostname);
二、配置schema.xml
<?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <schema name="mycatdb1" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn1"></schema> <schema name="mycatdb2" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn2"></schema> <schema name="mycatdb3" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn3"></schema> <schema name="mycatdb4" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn4"></schema> <schema name="mycatdb5" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn5"></schema> <schema name="mycatdb6" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn6"></schema> <schema name="mycatdb7" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn7"></schema> <schema name="mycatdb8" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn8"></schema> <schema name="mycatdb9" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn9"></schema> <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743" /> --> <dataNode name="dn1" dataHost="node1" database="testdb1" /> <dataNode name="dn2" dataHost="node1" database="testdb2" /> <dataNode name="dn3" dataHost="node1" database="testdb3" /> <dataNode name="dn4" dataHost="node2" database="testdb4" /> <dataNode name="dn5" dataHost="node2" database="testdb5" /> <dataNode name="dn6" dataHost="node2" database="testdb6" /> <dataNode name="dn7" dataHost="node3" database="testdb7" /> <dataNode name="dn8" dataHost="node3" database="testdb8" /> <dataNode name="dn9" dataHost="node3" database="testdb9" /> <!--<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">mycatdb1,mycatdb2,mycatdb3,mycatdb4,mycatdb5,mycatdb6,mycatdb7,mycatdb8,mycatdb9</property> <!-- 表级 DML 权限设置 --> <!-- <privileges check="false"> <schema name="TESTDB" dml="0110" > <table name="tb01" dml="0000"></table> <table name="tb02" dml="1111"></table> </schema> </privileges> --> </user>
四、启动mycat
/usr/local/mycat/bin/mycat start
查看mycat日志
STATUS | wrapper | 2018/11/21 17:07:24 | --> Wrapper Started as Daemon STATUS | wrapper | 2018/11/21 17:07:24 | Launching a JVM... INFO | jvm 1 | 2018/11/21 17:07:24 | OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=64M; support was removed in 8.0 INFO | jvm 1 | 2018/11/21 17:07:26 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org INFO | jvm 1 | 2018/11/21 17:07:26 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved. INFO | jvm 1 | 2018/11/21 17:07:26 | INFO | jvm 1 | 2018/11/21 17:07:30 | MyCAT Server startup successfully. see logs in logs/mycat.log
五、访问8066端口查看数据
[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb1.t01" mysql: [Warning] Using a password on the command line interface can be insecure. +-------+-------+-------+ | name1 | name2 | name3 | +-------+-------+-------+ | node1 | node1 | node1 | +-------+-------+-------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb2.t02" mysql: [Warning] Using a password on the command line interface can be insecure. +-------+-------+-------+ | name1 | name2 | name3 | +-------+-------+-------+ | node1 | node1 | node1 | +-------+-------+-------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb3.t03" mysql: [Warning] Using a password on the command line interface can be insecure. +-------+-------+-------+ | name1 | name2 | name3 | +-------+-------+-------+ | node1 | node1 | node1 | +-------+-------+-------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb4.t04" mysql: [Warning] Using a password on the command line interface can be insecure. +-------+-------+-------+ | name1 | name2 | name3 | +-------+-------+-------+ | node2 | node2 | node2 | +-------+-------+-------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb5.t05" mysql: [Warning] Using a password on the command line interface can be insecure. +-------+-------+-------+ | name1 | name2 | name3 | +-------+-------+-------+ | node2 | node2 | node2 | +-------+-------+-------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb6.t06" mysql: [Warning] Using a password on the command line interface can be insecure. +-------+-------+-------+ | name1 | name2 | name3 | +-------+-------+-------+ | node2 | node2 | node2 | +-------+-------+-------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb7.t07" mysql: [Warning] Using a password on the command line interface can be insecure. +-------+-------+-------+ | name1 | name2 | name3 | +-------+-------+-------+ | node3 | node3 | node3 | +-------+-------+-------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb8.t08" mysql: [Warning] Using a password on the command line interface can be insecure. +-------+-------+-------+ | name1 | name2 | name3 | +-------+-------+-------+ | node3 | node3 | node3 | +-------+-------+-------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb9.t09" mysql: [Warning] Using a password on the command line interface can be insecure. +-------+-------+-------+ | name1 | name2 | name3 | +-------+-------+-------+ | node3 | node3 | node3 | +-------+-------+-------+
数据查看正常,9个库分布在三个机器。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。