項(xiàng)目環(huán)境:
成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比敦煌網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式敦煌網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋敦煌地區(qū)。費(fèi)用合理售后完善,十多年實(shí)體公司更值得信賴。192.168.8.30 mycat
192.168.8.31 node1
192.168.8.32 node2
192.168.8.33 node3
三個(gè)節(jié)點(diǎn)MySQL均為單實(shí)例
一、創(chuàng)建測(cè)試數(shù)據(jù)
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> <!-- 表級(jí) DML 權(quán)限設(shè)置 --> <!-- <privileges check="false"> <schema name="TESTDB" dml="0110" > <table name="tb01" dml="0000"></table> <table name="tb02" dml="1111"></table> </schema> </privileges> --> </user>
四、啟動(dòng)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) /tupian/20230522/home.html 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
五、訪問(wèn)8066端口查看數(shù)據(jù)
[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 | +-------+-------+-------+
數(shù)據(jù)查看正常,9個(gè)庫(kù)分布在三個(gè)機(jī)器。
新聞名稱:MyCat分庫(kù)分表--實(shí)戰(zhàn)01--垂直分庫(kù)-創(chuàng)新互聯(lián)
分享網(wǎng)址:http://muchs.cn/article38/pcipp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、自適應(yīng)網(wǎng)站、靜態(tài)網(wǎng)站、網(wǎng)站排名、域名注冊(cè)、營(yíng)銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容