溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MyCat怎么實現(xiàn)MySQL一主兩從讀寫分離

發(fā)布時間:2021-08-30 21:12:15 來源:億速云 閱讀:162 作者:chen 欄目:MySQL數(shù)據(jù)庫

這篇文章主要介紹“MyCat怎么實現(xiàn)MySQL一主兩從讀寫分離”,在日常操作中,相信很多人在MyCat怎么實現(xiàn)MySQL一主兩從讀寫分離問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”MyCat怎么實現(xiàn)MySQL一主兩從讀寫分離”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

環(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)建測試庫

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標簽:schema name屬性指定邏輯庫名,dataNode屬性指定下邊的dataNode

      其中 checkSQLschema 表明是否檢查并過濾 SQL 中包含schema的情況,如邏輯庫為mycatdb1,則可能寫為 select * from mycatdb1.t11,此時會自動過濾 mycatdb1,SQL變?yōu)閟elect * from t11,若不會出現(xiàn)上述寫法,則可以關閉屬性為false。

      sqlMaxLimit默認返回的最大記錄數(shù)限制,MyCat1.4 版本里面,用戶的Limit參數(shù)會覆蓋掉MyCat的sqlMaxLimit默認設置

  • dataNode標簽:dataHost指定下邊的dataHost,database指定具體的database

  • dataHost標簽:balance指的負載均衡類型,switchType指的是切換的模式

      schema中的每一個dataHost中的host屬性值必須唯一,否則會出現(xiàn)主從在所有dataHost中全部切換的現(xiàn)象

其中,balance 指的負載均衡類型,目前的取值有 4 種:

1. balance="0", 不開啟讀寫分離機制,所有讀操作都發(fā)送到當前可用的 writeHost 上。

2. balance="1",全部的readHost與 stand by writeHost 參與select語句的負載均衡,簡單的說,當雙主雙從模式(M1>S1,M2->S2,并且 M1 與 M2 互為主備),正常情況下,M2,S1,S2 都參與select語句的負載均衡。

3. balance="2",所有讀操作都隨機的在 writeHost、readhost 上分發(fā)。

4. balance="3",所有讀請求隨機的分發(fā)到 wiriterHost 對應的 readhost 執(zhí)行,writerHost 不負擔讀壓力

因此,該配置文件中的 balance="1"意味著作為stand by writeHost的hostS1和hostS2將參與select語句的負載均衡,這就實現(xiàn)了主從的讀寫分離

switchType 指的是切換的模式,目前的取值也有 4 種:

1. switchType='-1' 表示不自動切換

2. switchType='1' 默認值,表示自動切換

3. switchType='2' 基于MySQL主從同步的狀態(tài)決定是否切換,心跳語句為 show slave status

MyCat1.4 開始支持MySQL主從復制狀態(tài)綁定的讀寫分離機制,讓讀更加安全可靠,配置如下:

MyCat心跳檢查語句配置為 show slave status,dataHost上定義兩個新屬性:switchType="2"與slaveThreshold="100",此時意味著開啟MySQL主從復制狀態(tài)綁定的讀寫分離與切換機制,MyCat 心跳機制通過檢測show slave status 中的"Seconds_Behind_Master", "Slave_IO_Running", "Slave_SQL_Running"

三個字段來確定當前主從同步的狀態(tài)以及 Seconds_Behind_Master 主從復制時延,當 Seconds_Behind_Master 大于 slaveThreshold 時,讀寫分離篩選器會過濾掉此Slave機器,防止讀到很久之前的舊數(shù)據(jù),而當主節(jié)點宕機后,切換邏輯會檢查Slave上的Seconds_Behind_Master 是否為 0,為 0 時則表示主從同步,可以安全切換,否則不會切換。

4. switchType='3'基于 MySQL galary cluster/PXC/mgr 的切換機制(適合集群)(1.4.1),心跳語句為 show status like 'wsrep%'。

四、配置server.xml

<user name="root" defaultAccount="true">
		<property name="password">mysql</property>
		<property name="schemas">mycatdb1,mycatdb2,mycatdb3</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>
	<user name="user">
		<property name="password">user</property>
		<property name="schemas">mycatdb1,mycatdb2,mycatdb3</property>
		<property name="readOnly">true</property>
	</user>

五、修改MyCat日志級別

vi log4j2.xml

修改<asyncRoot level="info" includeLocation="true">

為 <asyncRoot level="debug" includeLocation="true">

六、啟動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進程

[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,查看邏輯庫

[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)

八、讀寫分離驗證

[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

注意:這里的負載均衡并不是在slave1和slave2上邊輪詢,而是總體保持負載均衡。

[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 |
+--------+--------+--------+

九、主從切換測試

關閉master上的MySQL進程

[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 |
+--------+--------+--------+

短暫的連接失敗之后,寫操作連進slave1,主從切換成功。

到此,關于“MyCat怎么實現(xiàn)MySQL一主兩從讀寫分離”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI