這篇文章主要介紹“MyCat怎么實(shí)現(xiàn)MySQL一主兩從讀寫分離”,在日常操作中,相信很多人在MyCat怎么實(shí)現(xiàn)MySQL一主兩從讀寫分離問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”MyCat怎么實(shí)現(xiàn)MySQL一主兩從讀寫分離”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
創(chuàng)新互聯(lián)致力于網(wǎng)站設(shè)計(jì)、做網(wǎng)站,成都網(wǎng)站設(shè)計(jì),集團(tuán)網(wǎng)站建設(shè)等服務(wù)標(biāo)準(zhǔn)化,推過(guò)標(biāo)準(zhǔn)化降低中小企業(yè)的建站的成本,并持續(xù)提升建站的定制化服務(wù)水平進(jìn)行質(zhì)量交付,讓企業(yè)網(wǎng)站從市場(chǎng)競(jìng)爭(zhēng)中脫穎而出。 選擇創(chuàng)新互聯(lián),就選擇了安全、穩(wěn)定、美觀的網(wǎng)站建設(shè)服務(wù)!
環(huán)境搭建(一主兩從):
macat:192.168.8.30
master:192.168.8.31
slave1:192.168.8.32
slave2:192.168.8.33
工具包:
java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64
Mycat-server-1.6.6.1-release-20181031195535-linux.tar.gz
一、安裝JDK和MyCat
系統(tǒng)已安裝JDK,查看安裝路徑
[root@mycat ~]# java -version openjdk version "1.8.0_161" OpenJDK Runtime Environment (build 1.8.0_161-b14) OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
[root@mycat ~]# ls -l /usr/bin/java lrwxrwxrwx. 1 root root 22 Oct 22 10:30 /usr/bin/java -> /etc/alternatives/java
[root@mycat ~]# ls -l /etc/alternatives/java lrwxrwxrwx. 1 root root 71 Oct 22 10:30 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre/bin/java
安裝MyCat
cd /software tar zxvf Mycat-server-1.6.6.1-release-20181031195535-linux.tar.gz cp -r mycat /usr/local/
配置環(huán)境變量
[root@mycat ~]# cat ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64 export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre export MYCAT_HOME=/usr/local/mycat PATH=$PATH:/mysql/app/mysql/bin:/mysql/app/xtrabackup/bin:$HOME/bin:/usr/bin:/sbin:/bin:$MYCAT_HOME/bin:$JAVA_HOME/bin export PATH
二、創(chuàng)建測(cè)試庫(kù)
master創(chuàng)建,slave同步
create database testdb1; create table testdb1.t11(name1 varchar(40),name2 varchar(40),name3 varchar(40)); create database testdb2; create table testdb2.t21(name1 varchar(40),name2 varchar(40),name3 varchar(40)); create database testdb3; create table testdb3.t31(name1 varchar(40),name2 varchar(40),name3 varchar(40));
三、配置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> <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743" /> --> <dataNode name="dn1" dataHost="localhost1" database="testdb1" /> <dataNode name="dn2" dataHost="localhost1" database="testdb2" /> <dataNode name="dn3" dataHost="localhost1" database="testdb3" /> <!--<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="localhost1" 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"> <!-- can have multi read hosts --> <readHost host="192.168.8.32" url="192.168.8.32:3306" user="root" password="mysql" /> <readHost host="192.168.8.33" url="192.168.8.33:3306" user="root" password="mysql" /> </writeHost> <writeHost host="192.168.8.32" url="192.168.8.32:3306" user="root" password="mysql" /> <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> --> </dataHost> <!-- <dataHost name="sequoiadb1" maxCon="1000" minCon="1" balance="0" dbType="sequoiadb" dbDriver="jdbc"> <heartbeat> </heartbeat> <writeHost host="hostM1" url="sequoiadb://1426587161.dbaas.sequoialab.net:11920/SAMPLE" user="jifeng" password="jifeng"></writeHost> </dataHost> <dataHost name="oracle1" maxCon="1000" minCon="1" balance="0" writeType="0" dbType="oracle" dbDriver="jdbc"> <heartbeat>select 1 from dual</heartbeat> <connectionInitSql>alter session set nls_date_format='yyyy-mm-dd hh34:mi:ss'</connectionInitSql> <writeHost host="hostM1" url="jdbc:oracle:thin:@127.0.0.1:1521:nange" user="base" password="123456" > </writeHost> </dataHost> <dataHost name="jdbchost" maxCon="1000" minCon="1" balance="0" writeType="0" dbType="MongoDB" dbDriver="jdbc"> <heartbeat>select user()</heartbeat> <writeHost host="hostM" url="mongodb://192.168.0.99/test" user="admin" password="123456" ></writeHost> </dataHost> <dataHost name="sparksql" maxCon="1000" minCon="1" balance="0" dbType="spark" dbDriver="jdbc"> <heartbeat> </heartbeat> <writeHost host="hostM1" url="jdbc:hive2://feng01:10000" user="jifeng" password="jifeng"></writeHost> </dataHost> --> <!-- <dataHost name="jdbchost" maxCon="1000" minCon="10" balance="0" dbType="mysql" dbDriver="jdbc"> <heartbeat>select user()</heartbeat> <writeHost host="hostM1" url="jdbc:mysql://localhost:3306" user="root" password="123456"> </writeHost> </dataHost> --> </mycat:schema>
schema標(biāo)簽:schema name屬性指定邏輯庫(kù)名,dataNode屬性指定下邊的dataNode
其中 checkSQLschema 表明是否檢查并過(guò)濾 SQL 中包含schema的情況,如邏輯庫(kù)為mycatdb1,則可能寫為 select * from mycatdb1.t11,此時(shí)會(huì)自動(dòng)過(guò)濾 mycatdb1,SQL變?yōu)閟elect * from t11,若不會(huì)出現(xiàn)上述寫法,則可以關(guān)閉屬性為false。
sqlMaxLimit默認(rèn)返回的最大記錄數(shù)限制,MyCat1.4 版本里面,用戶的Limit參數(shù)會(huì)覆蓋掉MyCat的sqlMaxLimit默認(rèn)設(shè)置
dataNode標(biāo)簽:dataHost指定下邊的dataHost,database指定具體的database
dataHost標(biāo)簽:balance指的負(fù)載均衡類型,switchType指的是切換的模式
schema中的每一個(gè)dataHost中的host屬性值必須唯一,否則會(huì)出現(xiàn)主從在所有dataHost中全部切換的現(xiàn)象
其中,balance 指的負(fù)載均衡類型,目前的取值有 4 種:
1. balance="0", 不開啟讀寫分離機(jī)制,所有讀操作都發(fā)送到當(dāng)前可用的 writeHost 上。
2. balance="1",全部的readHost與 stand by writeHost 參與select語(yǔ)句的負(fù)載均衡,簡(jiǎn)單的說(shuō),當(dāng)雙主雙從模式(M1>S1,M2->S2,并且 M1 與 M2 互為主備),正常情況下,M2,S1,S2 都參與select語(yǔ)句的負(fù)載均衡。
3. balance="2",所有讀操作都隨機(jī)的在 writeHost、readhost 上分發(fā)。
4. balance="3",所有讀請(qǐng)求隨機(jī)的分發(fā)到 wiriterHost 對(duì)應(yīng)的 readhost 執(zhí)行,writerHost 不負(fù)擔(dān)讀壓力
因此,該配置文件中的 balance="1"意味著作為stand by writeHost的hostS1和hostS2將參與select語(yǔ)句的負(fù)載均衡,這就實(shí)現(xiàn)了主從的讀寫分離
switchType 指的是切換的模式,目前的取值也有 4 種:
1. switchType='-1' 表示不自動(dòng)切換
2. switchType='1' 默認(rèn)值,表示自動(dòng)切換
3. switchType='2' 基于MySQL主從同步的狀態(tài)決定是否切換,心跳語(yǔ)句為 show slave status
MyCat1.4 開始支持MySQL主從復(fù)制狀態(tài)綁定的讀寫分離機(jī)制,讓讀更加安全可靠,配置如下:
MyCat心跳檢查語(yǔ)句配置為 show slave status,dataHost上定義兩個(gè)新屬性:switchType="2"與slaveThreshold="100",此時(shí)意味著開啟MySQL主從復(fù)制狀態(tài)綁定的讀寫分離與切換機(jī)制,MyCat 心跳機(jī)制通過(guò)檢測(cè)show slave status 中的"Seconds_Behind_Master", "Slave_IO_Running", "Slave_SQL_Running"
三個(gè)字段來(lái)確定當(dāng)前主從同步的狀態(tài)以及 Seconds_Behind_Master 主從復(fù)制時(shí)延,當(dāng) Seconds_Behind_Master 大于 slaveThreshold 時(shí),讀寫分離篩選器會(huì)過(guò)濾掉此Slave機(jī)器,防止讀到很久之前的舊數(shù)據(jù),而當(dāng)主節(jié)點(diǎn)宕機(jī)后,切換邏輯會(huì)檢查Slave上的Seconds_Behind_Master 是否為 0,為 0 時(shí)則表示主從同步,可以安全切換,否則不會(huì)切換。
4. switchType='3'基于 MySQL galary cluster/PXC/mgr 的切換機(jī)制(適合集群)(1.4.1),心跳語(yǔ)句為 show status like 'wsrep%'。
四、配置server.xml
<user name="root" defaultAccount="true"> <property name="password">mysql</property> <property name="schemas">mycatdb1,mycatdb2,mycatdb3</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> <user name="user"> <property name="password">user</property> <property name="schemas">mycatdb1,mycatdb2,mycatdb3</property> <property name="readOnly">true</property> </user>
五、修改MyCat日志級(jí)別
vi log4j2.xml
修改<asyncRoot level="info" includeLocation="true">
為 <asyncRoot level="debug" includeLocation="true">
六、啟動(dòng)mycat
[root@mycat conf]# /usr/local/mycat/bin/mycat start Starting Mycat-server...
查看日志
STATUS | wrapper | 2018/11/21 11:08:50 | --> Wrapper Started as Daemon STATUS | wrapper | 2018/11/21 11:08:51 | Launching a JVM... INFO | jvm 1 | 2018/11/21 11:08:51 | OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=64M; support was removed in 8.0 INFO | jvm 1 | 2018/11/21 11:08:54 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org INFO | jvm 1 | 2018/11/21 11:08:54 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved. INFO | jvm 1 | 2018/11/21 11:08:54 | INFO | jvm 1 | 2018/11/21 11:08:58 | MyCAT Server startup successfully. see logs in logs/mycat.log
查看端口
[root@mycat conf]# netstat -an|grep 8066 tcp6 0 0 :::8066
查看mycat進(jìn)程
[root@mycat conf]# ps -ef|grep mycat avahi 646 1 0 09:56 ? 00:00:03 avahi-daemon: running [mycat.local] root 2653 1 0 11:08 ? 00:00:00 /usr/local/mycat/bin/./wrapper-linux-x86-64 /usr/local/mycat/conf/wrapper.conf wrapper.syslog.ident=mycat wrapper.pidfile=/usr/local/mycat/logs/mycat.pid wrapper.daemonize=TRUE wrapper.lockfile=/var/lock/subsys/myca root 2655 2653 7 11:08 ? 00:00:07 java -DMYCAT_HOME=. -server -XX:MaxPermSize=64M -XX:+AggressiveOpts -XX:MaxDirectMemorySize=2G -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1984 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Xmx4G -Xms1G -Djava.library.path=lib -classpath lib/wrapper.jar:conf:lib/asm-4.0.jar:lib/commons-collections-3.2.1.jar:lib/commons-lang-2.6.jar:lib/curator-client-2.11.0.jar:lib/curator-framework-2.11.0.jar:lib/curator-recipes-2.11.0.jar:lib/disruptor-3.3.4.jar:lib/dom4j-1.6.1.jar:lib/druid-1.0.26.jar:lib/ehcache-core-2.6.11.jar:lib/fastjson-1.2.12.jar:lib/guava-19.0.jar:lib/hamcrest-core-1.3.jar:lib/hamcrest-library-1.3.jar:lib/jline-0.9.94.jar:lib/joda-time-2.9.3.jar:lib/jsr305-2.0.3.jar:lib/kryo-2.10.jar:lib/leveldb-0.7.jar:lib/leveldb-api-0.7.jar:lib/libwrapper-linux-ppc-64.so:lib/libwrapper-linux-x86-32.so:lib/libwrapper-linux-x86-64.so:lib/log4j-1.2-api-2.5.jar:lib/log4j-1.2.17.jar:lib/log4j-api-2.5.jar:lib/log4j-core-2.5.jar:lib/log4j-slf4j-impl-2.5.jar:lib/mapdb-1.0.7.jar:lib/minlog-1.2.jar:lib/mongo-java-driver-2.11.4.jar:lib/Mycat-server-1.6.6.1-release.jar:lib/mysql-binlog-connector-java-0.16.1.jar:lib/mysql-connector-java-5.1.35.jar:lib/netty-3.7.0.Final.jar:lib/netty-buffer-4.1.9.Final.jar:lib/netty-common-4.1.9.Final.jar:lib/objenesis-1.2.jar:lib/reflectasm-1.03.jar:lib/sequoiadb-driver-1.12.jar:lib/slf4j-api-1.6.1.jar:lib/univocity-parsers-2.2.1.jar:lib/velocity-1.7.jar:lib/wrapper.jar:lib/zookeeper-3.4.6.jar -Dwrapper.key=G87oQ7EZv67RXK9D -Dwrapper.port=32000 -Dwrapper.jvm.port.min=31000 -Dwrapper.jvm.port.max=31999 -Dwrapper.pid=2653 -Dwrapper.version=3.2.3 -Dwrapper.native_library=wrapper -Dwrapper.service=TRUE -Dwrapper.cpu.timeout=10 -Dwrapper.jvmid=1 org.tanukisoftware.wrapper.WrapperSimpleApp io.mycat.MycatStartup start
七、登錄mysql,查看邏輯庫(kù)
[root@mycat ~]# mysql -uroot -pmysql -P8066 -h292.168.8.30 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.29-mycat-1.6.6.1-release-20181031195535 MyCat Server (OpenCloudDB) Copyright (c) 2009-2018 Percona LLC and/or its affiliates Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +----------+ | DATABASE | +----------+ | mycatdb1 | | mycatdb2 | | mycatdb3 | +----------+ 3 rows in set (0.01 sec) mysql> use mycatdb1; 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_testdb1 | +-------------------+ | t11 | +-------------------+ 1 row in set (0.04 sec) mysql> select * from t11; Empty set (0.22 sec)
八、讀寫分離驗(yàn)證
[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave1 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave1 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave1 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave2 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave1 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave2 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave2 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave2 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave1 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave2 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave1 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave1 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave2 | +------------+ [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select @@hostname" mysql: [Warning] Using a password on the command line interface can be insecure. +------------+ | @@hostname | +------------+ | slave2 |
可以看到讀操作全部在slave1和slave2
注意:這里的負(fù)載均衡并不是在slave1和slave2上邊輪詢,而是總體保持負(fù)載均衡。
[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb1.t11" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+--------+--------+ | name1 | name2 | name3 | +--------+--------+--------+ | master | master | master | | master | master | master | | master | master | master | | master | master | master | | master | master | master | | master | master | master | | master | master | master | | master | master | master | | master | master | master | +--------+--------+--------+
九、主從切換測(cè)試
關(guān)閉master上的MySQL進(jìn)程
[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1184 (HY000) at line 1: java.net.ConnectException: Connection refused [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1184 (HY000) at line 1: java.net.ConnectException: Connection refused [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "insert into mycatdb1.t11 values(@@hostname,@@hostname,@@hostname)"mysql: [Warning] Using a password on the command line interface can be insecure. [root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb1.t11" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+--------+--------+ | name1 | name2 | name3 | +--------+--------+--------+ | master | master | master | | master | master | master | | master | master | master | | master | master | master | | master | master | master | | master | master | master | | master | master | master | | master | master | master | | master | master | master | | slave1 | slave1 | slave1 | | slave1 | slave1 | slave1 | | slave1 | slave1 | slave1 | +--------+--------+--------+
短暫的連接失敗之后,寫操作連進(jìn)slave1,主從切換成功。
到此,關(guān)于“MyCat怎么實(shí)現(xiàn)MySQL一主兩從讀寫分離”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
當(dāng)前名稱:MyCat怎么實(shí)現(xiàn)MySQL一主兩從讀寫分離
網(wǎng)站鏈接:http://jinyejixie.com/article46/igoihg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、網(wǎng)站設(shè)計(jì)、定制網(wǎng)站、移動(dò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)