iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >MyCat怎么实现MySQL一主两从读写分离
  • 538
分享到

MyCat怎么实现MySQL一主两从读写分离

2024-04-02 19:04:59 538人浏览 安东尼
摘要

这篇文章主要介绍“MyCat怎么实现Mysql一主两从读写分离”,在日常操作中,相信很多人在MyCat怎么实现mysql一主两从读写分离问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大

这篇文章主要介绍“MyCat怎么实现Mysql一主两从读写分离”,在日常操作中,相信很多人在MyCat怎么实现mysql一主两从读写分离问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”MyCat怎么实现Mysql一主两从读写分离”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

环境搭建(一主两从):

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

系统已安装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/

配置环境变量

[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

二、创建测试

master创建,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变为select * from t11,若不会出现上述写法,则可以关闭属性为false。

      sqlMaxLimit默认返回的最大记录数限制,MyCat1.4 版本里面,用户的Limit参数会覆盖掉MyCat的sqlMaxLimit默认设置

  • dataNode标签:dataHost指定下边的dataHost,database指定具体的database

  • dataHost标签:balance指的负载均衡类型,switchType指的是切换的模式

      schema中的每一个dataHost中的host属性值必须唯一,否则会出现主从在所有dataHost中全部切换的现象

其中,balance 指的负载均衡类型,目前的取值有 4 种:

1. balance="0", 不开启读写分离机制,所有读操作都发送到当前可用的 writeHost 上。

2. balance="1",全部的readHost与 stand by writeHost 参与select语句的负载均衡,简单的说,当双主双从模式(M1>S1,M2->S2,并且 M1 与 M2 互为主备),正常情况下,M2,S1,S2 都参与select语句的负载均衡。

3. balance="2",所有读操作都随机的在 writeHost、readhost 上分发。

4. balance="3",所有读请求随机的分发到 wiriterHost 对应的 readhost 执行,writerHost 不负担读压力

因此,该配置文件中的 balance="1"意味着作为stand by writeHost的hostS1和hostS2将参与select语句的负载均衡,这就实现了主从的读写分离

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

1. switchType='-1' 表示不自动切换

2. switchType='1' 默认值,表示自动切换

3. switchType='2' 基于MySQL主从同步的状态决定是否切换,心跳语句为 show slave status

MyCat1.4 开始支持MySQL主从复制状态绑定的读写分离机制,让读更加安全可靠,配置如下:

MyCat心跳检查语句配置为 show slave status,dataHost上定义两个新属性:switchType="2"与slaveThreshold="100",此时意味着开启MySQL主从复制状态绑定的读写分离与切换机制,MyCat 心跳机制通过检测show slave status 中的"Seconds_Behind_Master", "Slave_IO_Running", "Slave_SQL_Running"

三个字段来确定当前主从同步的状态以及 Seconds_Behind_Master 主从复制时延,当 Seconds_Behind_Master 大于 slaveThreshold 时,读写分离筛选器会过滤掉此Slave机器,防止读到很久之前的旧数据,而当主节点宕机后,切换逻辑会检查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怎么实现MySQL一主两从读写分离”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注编程网网站,小编会继续努力为大家带来更多实用的文章!

您可能感兴趣的文档:

--结束END--

本文标题: MyCat怎么实现MySQL一主两从读写分离

本文链接: https://www.lsjlt.com/news/59851.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • MyCat怎么实现MySQL一主两从读写分离
    这篇文章主要介绍“MyCat怎么实现MySQL一主两从读写分离”,在日常操作中,相信很多人在MyCat怎么实现MySQL一主两从读写分离问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大...
    99+
    2022-10-18
  • MyCat如何实现MySQL双主一从读写分离
    这篇文章给大家分享的是有关MyCat如何实现MySQL双主一从读写分离的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。1)配置server.xml<user nam...
    99+
    2022-10-18
  • Mycat中间件实现Mysql主从读写分离
    环境规划: IP地址 主机名 角色 备注 10.4.132.50 k8s01 mycat,master 10.4.132.42 k8s02 slave ...
    99+
    2022-10-18
  • Linux如何使用 MyCat 实现 MySQL 主从读写分离
    目录Linux-使用 MyCat 实现 MySQL 主从读写分离 一、MySQL 读写分离1、MySQL 读写分离的概述2、读写分离工作原理3、为什么要读写分离3、实现读写分离的方式...
    99+
    2022-11-12
  • mysql主从配置实现一主一从读写分离
    主从介绍Mysql主从又叫Replication、AB复制。简单讲就是A与B两台机器做主从后,在A上写数据,另外一台B也会跟着写数据,实现数据实时同步 mysql主从是基于binlog,主上需开启binlo...
    99+
    2022-10-18
  • mysql+mycat实现读写分离
    centos7 master slave mycat1.6 client 192.168.41.10 192.168.41.11 192.168.41.12 192.168.41.13 ...
    99+
    2022-10-18
  • Redis5怎么配置一主两从读写分离
    本篇内容介绍了“Redis5怎么配置一主两从读写分离”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!实验环境...
    99+
    2022-10-18
  • MyCAT实现MySQL的读写分离
    在MySQL中间件出现之前,对于MySQL主从集群,如果要实现其读写分离,一般是在程序端实现,这样就带来一个问题,即数据库和程序的耦合度太高,如果我数据库的地址发生改变了,那么我程序端也要进行相应的修改,如...
    99+
    2022-10-18
  • 使用Mycat怎么实现MySQL读写分离
    今天就跟大家聊聊有关使用Mycat怎么实现MySQL读写分离,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。搭建环境操作系统:CentOS-6.5-x...
    99+
    2022-10-18
  • MyCat中怎么实现读写分离
    这期内容当中小编将会给大家带来有关MyCat中怎么实现读写分离,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。1、mycat实现读写分离这里没有用到mysql03主机,读写...
    99+
    2022-10-18
  • Django搭建MySQL主从实现读写分离
    目录一、MySQL主从搭建操作步骤二、Django实现读写分离自动指定一、MySQL主从搭建 主从配置原理: 主库写日志到 BinLog 从库开个 IO 线程读取...
    99+
    2022-11-12
  • Redis主从实现读写分离
    前言 大家在工作中可能会遇到这样的需求,即Redis读写分离,目的是为了压力分散化。下面我将为大家介绍借助AWS的ELB实现读写分离,以写主读从为例。 实现 引用库文件 <!-- redis客...
    99+
    2022-06-04
    主从 Redis
  • MySQL中怎么实现主从复制及读写分离
    MySQL中怎么实现主从复制及读写分离?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。一、相关概述主从复制:主数据库(Master)发送更新事件到从数据库(Slave),从数...
    99+
    2023-06-14
  • mycat基础实验之主从配置读写分离和分表
    mycat实验之主从配置读写分离和分表1.实验环境:vmware虚机3个   (虚机太少了,电脑有点吃力,3个虚机只能达到基本的测试)系统centos7    &nb...
    99+
    2022-10-18
  • Mycat如何实现Mysql集群读写分离
    这篇文章给大家分享的是有关Mycat如何实现Mysql集群读写分离的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。MySQL 读写分离的概述MySQL 作为目前世界上使用最广泛的免...
    99+
    2022-10-19
  • 怎么在Mysql中实现主从复制与读写分离
    这期内容当中小编将会给大家带来有关怎么在Mysql中实现主从复制与读写分离,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。文章思维导图为什么使用主从复制、读写分离主从复制、读写分离一般是一起使用的。目的很简...
    99+
    2023-06-14
  • mysql数据库中怎么利用mycat实现读写分离
    这期内容当中小编将会给大家带来有关mysql数据库中怎么利用mycat实现读写分离,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。1、部署mycat下载 [root@myc...
    99+
    2022-10-18
  • mysql主从基于docker和django实现读写分离
    目录1.主从搭建实操2.django实现读写分离settings.py配置手动指定读写分离自动指定(写router和配置setting)更细粒度(分库分表时需要)在数据库迁移时,可以指定把哪个app的表结构迁移到哪个库1...
    99+
    2022-08-25
  • amoeba实现mysql读写分离+主从复制架构
    一、环境系统:centos6.5mysql版本:mysql5.6master服务器:192.168.1.21slave服务器: 192.168.1.100master写 slave读二、实现mysql主从复...
    99+
    2022-10-18
  • SpringBoot中怎么利用MyCat实现读写分离
    SpringBoot中怎么利用MyCat实现读写分离,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。MySQL配置主从关系说明 192.168.0.10...
    99+
    2023-06-16
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作