Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The principle of MySQL Master-Slave replication and read-write Separation

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The main purpose of this article is to share the principle of MySQL master-slave replication and read-write separation. This paper also introduces how to configure and verify the experiment of master-slave replication and read-write separation. I hope you can get something through this article.

Separation of MySQL master-slave replication and reading and writing I. preface

We have already had a preliminary understanding of MySQL database installation, command, backup, index, transaction and storage engine, but today we will understand what is the master-slave replication and read-write separation of MySQL database from a macro point of view.

Second, scene description

In the actual production environment, if the read and write of MySQL database are operated on one server, it can not be satisfied in many aspects, such as security, high availability, high concurrency and so on; and this requires master-slave replication and read-write separation of MySQL database.

We use an architecture diagram to elicit the principle and function of master-slave replication of MySQL databases, as shown in the following figure:

Server role:

MySQL master server: responsible for data writing

MySQL slave server: synchronizes the data of the master server and performs round robin reading of the data

Then these three MySQL servers with the same service are called "MySQL clusters". We can see from the above figure that this arrangement realizes the separation of data reading and writing on the basis of data synchronization, which not only ensures the reliability of the data, but also greatly reduces the pressure on the main server.

Let's introduce the master-slave replication and read-write separation of MySQL one by one and give an example of configuration.

Third, the principle of MySQL master-slave replication

There is a close relationship between MySQL master-slave replication and read-write separation. It can be said that the implementation of MySQL read-write separation needs to be based on master-slave replication.

The type of replication supported by 3.1MySQL is statement-based replication;-- based on the replication form of SQL commands, SQL commands are used to perform replication with high efficiency;-- replicating the contents of database changes, rather than executing commands with mixed types of replication -- replication of statement type is used by default, and the working process of row-based replication 3.2MySQL replication is carried out if it is found that it cannot be replicated due to uncertain problems and other reasons.

We use the following figure to understand how the MySQL master and slave servers perform replication synchronization.

1) first of all, when the MySQL master server updates the database or other database-related operations, it records these changes in the binary log file (which we described in the previous incremental backup and recovery article, the settings of log-bin and how to use the mysqladmin command to refresh the log. When the log is written, the main server tells the storage engine to commit the transaction

2) the MySQL slave server copies the binary log file (Binary log) of the master server to the relay log (Relay log). Relay logs are usually stored in the system cache, so the overhead of relay logs is very small.

3) read events from the relay log from the server through its own thread, and update its own log file to make it consistent with the data in the master server.

Ps: an important limitation in the replication process is that replication on the slave server is serialized, which means that parallel update operations on the master server cannot operate in parallel on the slave server.

Fourth, MySQL master-slave replication configuration process and actual operation 4.1 the environment required for master-slave replication

List of required devices (we simulated the configuration on the virtual machine):

Centos7 1: as the master server-master,ip address is 192.168.68.133

Two Centos7: as slave servers-- the addresses of slave1 and slave2IP are 192.168.68.129 and 192.168.68.132 respectively.

Required installation services:

Install and configure ntp services, all with the MySQL5.7 version of the database installed

4.2 Master-slave replication specific process step 4.2.1 preparation work

First of all, let's think of the recovery operation of incremental backup. we all rely on the binary log files in the data directory and are implemented in two ways, one of which is based on the time node. Then we need to do MySQL master-slave server replication, we need to synchronize the system time of all MySQL servers first.

4.2.1.1 configuration of primary server preparation

1) set the server name to distinguish

Hostnamectl set-hostname mastersu

2) install and configure ntp service

Yum install ntp-y # modify the ntp service configuration file by adding the following two sentences: vim / etc/ntp.confserver 127.127.68.0 # server local network segment. 127.127 means 192.168fudge 127.127.68.0 stratum 8 # time zone setting (East Zone 8) # Save and exit systemctl start ntpd# can use netstat-nutp | grep ntpd command to check the service enabled status

3) turn off the firewall and SELinux function

Systemctl stop firewalldsetenforce 04.2.1.2 configuration of preparation for two slave servers (the two steps are the same)

1) Server name setting

Hostnamectl set-hostname slave1 (slave2) su

2) install ntp and ntpdate services from the server and start the service

Yum install ntp ntpdate-ysystemctl start ntpd

3) two servers turn off firewall and SELinux functions from the server

Systemctl stop firewalldsetenforce 0

4) use the ntpdate command for time synchronization

[root@slave1] # / usr/sbin/ntpdate 192.168.68.133 9 Jan 15:35:13 ntpdate [67450]: the NTP socket is in use, configuration of exiting4.2.2MySQL Services 4.2.2.1 Modification and configuration of MySQL on the main server

1) modify the main configuration file of mysql and restart the mysql service

The vim / etc/my.cnf# configuration is as follows: log-bin = master-bin # binary log file master-bin can set server-id = 1 # server's id number to distinguish log-slave-updates=true # from enabling the log update function from the server (combined with replication process connection) systemctl restart mysqld.service

2) enter the database for permission setting (authorization) and refresh

[root@lokott] # mysql-uroot-pEnter password: Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 3Server version: 5.7.17-log Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c' to clear the current input statement.mysql > grant replication slave on *. * to 'myslave'@'192.168.68.%' identified by' 123456 refresh system permissions table Query OK, 0 rows affected (0.00 sec) mysql > show master status, 0 rows affected, 1 warning (0.00 sec) mysql > flush privileges;# +-+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +- -+ | master-bin.000001 | 603 | +- -+ 1 row in set (0.00 sec)

Pay attention to the core command: the interpretation of the authorization command, and the above location Position record data 603

Command format:

Grant replication slave on *. * to 'myslave'@'192.168.68.%' identified by' 123456 replica alternate grant-- the authorization command replication slave replicates the operation from the server *. * represents all databases and all tables

The specific meaning is: the host (server) of the 192.168.68.0 network segment is assigned to replicate (synchronize) all the database data of the master server.

4.2.2.2 Modification and configuration of MySQL from the server

1) modify the main configuration file and restart the service

The vim / etc/my.cnf# configuration is as follows: log-bin = mysql-binserver-id = 2relay-log = relay-log-bin # Relay Log relay-log-index = slave-relay-log-bin.index # Index File # Save exit restart systemctl restart mysqld.service

2) enter database configuration synchronization

[root@slave1] # mysql-uroot-p. # omit some contents mysql > change master to master_host='192.168.68.133',master_user='myslave',master_password='123456',master_log_file='master-bin.000001',master_log_pos=603;Query OK, 0 rows affected, 2 warnings (0.01 sec) mysql > start slave Query OK 0 rows affected (0.00 sec) mysql > show slave status\ gateway * 1. Row * * Slave_IO_State: Waiting for master to send event Master_Host: 192.168.68.133 Master_ User: myslave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000001 Read_Master_Log_Pos: 603 Relay_Log_File: relay-log-bin.000002 Relay_Log_Pos: 321 Relay_Master_Log_File: master-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes... # the two lines above indicate that the IO thread and database SQL statements given from the server are running. Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec) 4.2.3 testing and verification of master-slave replication

Create a new database on the primary server, create new tables and data; view it on the server

Primary server:

Create database test;Query OK, 1 row affected (0.00 sec)

Slave1 query from the service:

Mysql > show databases;+-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | sys | | test | +-+ 5 rows in set (0.00 sec) mysql > exitBye [root@slave1 ~] #

Query from the server slave2:

Mysql > show databases +-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | sys | | test | +-+ 5 rows in set (0.00 sec) mysql > exitBye [root@slave2 ~] # 4.3 Master-Slave replication Summary

This configuration implements the replication operation of the slave server through the permissions given by the master server. we need to understand the principle of master-slave replication and its replication process through the experimental configuration. Only when we understand how to perform master-slave replication of MySQL database can we understand and implement the configuration operation of MySQL read-write separation.

Fifth, the principle of MySQL separation of reading and writing.

The principle of read-write separation is simply to implement the function of writing data on the master server and reading data in turn from the server in the figure above.

Let's use the following figure to understand the process of separation of reading and writing.

Based on the implementation of the proxy layer: the agent is generally located between the client and the server, and the proxy server receives the client request and forwards it to the back-end database. There are two representative programs.

1) MySQL_Proxy: SQL is judged by the lua script that comes with it.

2) Amoeba:Java language development, Alibaba uses it in the production environment, does not support transactions and stored procedures

VI. MySQL read-write separation configuration process and actual operation

Environment: subsequent companion configuration based on the above master-slave replication process

Add devices: Centos7 two: one as an Amoeba proxy server and the other as a client test server.

Required software packages: jdk and amoeba related environments and applications need to be installed on the Amoeba proxy server (amoeba is developed using Java)

1) install jdk environment and ameoba environment

[root@amoeba ~] # cd tar/ [root@amoeba tar] # lsamoeba-mysql-binary-2.2.0.tar.gz jdk-6u14-linux-x64.bin cd tar/ ls cp jdk-6u14-linux-x64.bin / usr/local/ cd / usr/local/ chmod + x jdk-6u14-linux-x64.bin. / jdk-6u14-linux-x64.bin mv jdk1.6.0_14/ / usr/local/jdk1.6 vim / etc/profile # add the following lines of export JAVA_HOME=/usr/local/jdk1.6 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib export PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin/:$PATH:$HOME/bin export AMOEBA_HOME=/usr/local/amoeba export PATH=$PATH:$AMOEBA_HOME/bin source / etc/profile mkdir / usr/local/amoeba # go back to the archive directory and extract amoeba tar zxf amoeba-mysql-binary-2.2.0.tar.gz-C / usr/local/amoeba cd / usr/local/

2) configure parameters related to amoeba

The configuration path is in / usr/local/amoeba/conf and the configuration file is ameoba.xml,dbServers.xml. The former is the amoeba main configuration file (remember tomcat? The latter is the relevant configuration file for the database server

1. Change ameoba.xml

30 amoeba31 32 123456#user is the identity name under which we log in to the amoeba proxy server on the client side, and password is the login password Later, we will log in to 15 master116 117 master118 slaves119 # defaultPool on the client side to indicate the default server writePool indicates the specified write server (group), readPool indicates the specified read server (group), and slaves will be configured in the dbServers.xml file

2. Change dbServers.xml

26 test 27 28 29 123123 45 46 47 48 192.168.68.133 49 50 51 52 53 54 55 192.168.68.129 56 57 58 59 60 61 62 192.168.68.132 63 64 65 66 67 68 69 1 70 71 72 slave1 Slave2 73 74

3. Enable amoeba (you can view the port netstat-natp in another terminal | grep 8066)

[root@amoeba bin] # amoeba start & [1] 121608 [root@amoeba bin] # log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 INFO context.MysqlRuntimeContext-Amoeba for Mysql current versoin=5.1.45-mysql-amoeba-proxy-2.2.0log4j:WARN ip access config load completed from file:/usr/local/amoeba/conf/access_list.conf2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01-1008 log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml2020-01- On 0.0.0.0Unix 0.0.0Amoeba Monitor Server listening on 8066.2020-01-1008VOV 20VO3567 INFO net.ServerableConnectionManager-Amoeba Monitor Server listening on / 127.0.0.1Rose 39466.

4. Install the mysql database on the client client and log in to view

[root@localhost] # mysql-u amoeba-p123456-h 192.168.68.144-P8066mysql: [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 2023306452Server version: 5.1.45-mysql-amoeba-proxy-2.2.0 Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.mysql > show databases +-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | sys | | test | +-+ 5 rows in set (0.00 sec) mysql > use test;Database changedmysql > show tables Empty set (0.01 sec) # because we haven't created how-to tables and data at this time, we can't see any data on the client.

5. We create a table on the master server and check whether the table exists on the slave server. If it exists, the master-slave replication is normal.

Primary server:

Mysql > use test;Database changedmysql > create table info (id int (5) not null primary key auto_increment,name varchar (10) not null); Query OK, 0 rows affected (0.02 sec) mysql > desc info +-+ | Field | Type | Null | Key | Default | Extra | + -+-+ | id | int (5) | NO | PRI | NULL | auto_increment | | name | varchar (10) | NO | | NULL | | + -+ 2 rows in set (0.01sec) mysql > select * from info Empty set (0.00 sec)

From the server:

[root@slave1] # mysql-uroot-pEnter password: Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 14Server version: 5.7.17-log Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.mysql > show databases +-+ | Database | +-+ | information_schema | | mysql | | performance_schema | | sys | | test | +-+ 5 rows in set (0.01sec) mysql > use testReading table information for Completion of table and column namesYou can turn off this feature to get a quicker startup with-ADatabase changedmysql > show tables +-+ | Tables_in_test | +-+ | info | +-+ 1 row in set (0.00 sec)

6. View the table on the client

Mysql > show tables;Empty set (0.01sec) mysql > show tables;+-+ | Tables_in_test | +-+ | info | +-+ 1 row in set (0.00 sec)

7. So how do we verify the separation of read and write? Remember our start slave command on the slave server? We can stop master-slave replication and use stop slave.

Mysql > stop slave;Query OK, 0 rows affected (0.01 sec)

8. We insert new data on the client side and view it on the master and slave servers.

Client side:

Mysql > insert into info (name) values ('zhangsan'); Query OK, 1 row affected (0.01 sec) mysql > select * from info;+----+-+ | id | name | +-- +-+ | 2 | zhangsan | +-+ 1 row in set (0.00 sec)

Primary server:

Mysql > select * from info;+----+-+ | id | name | +-+-+ | 2 | zhangsan | +-+-+ 1 row in set (0.00 sec)

From the server:

Mysql > select * from info;Empty set (0.00 sec) Summary of master-slave server write separation

From the above experiments, we can draw the conclusion that after the configuration of master-slave replication and write separation, we can write data on the master server. After the master server writes, the slave server replicates (start slave) through the master-slave replication process, because we cannot stop slave (stop master-slave replication) in the production environment. But in order to verify the principle of read-write separation, we have to stop slave first.

Let's verify the read separation.

We write some data separately from the server (the two servers write differently from the server)

Slave1:

Mysql > insert into info (name) values ('lisi'); Query OK, 1 row affected (0.00 sec) mysql > select * from info;+----+-+ | id | name | +-- +-+ | 1 | lisi | +-+ 1 row in set (0.00 sec)

Slave2:

Mysql > insert into info (name) values ('wangwu'); Query OK, 1 row affected (0.00 sec) mysql > select * from info;+----+-+ | id | name | +-- +-+ | 1 | wangwu | +-+ 1 row in set (0.00 sec)

Client query: (there may be a problem because the auto_increment auto-increment column is used)

So we turn on replication on the slave server, modify the fields on the master-slave server, then turn off replication on the slave server, rewrite different data, and view it on the client side.

Two slave servers:

Mysql > start slave;Query OK, 0 rows affected (0.01 sec)

Primary server:

Mysql > alter table info modify id int (5) not null;Query OK, 1 row affected (0.02 sec) Records: 1 Duplicates: 0 Warnings: 0mysql > desc info +-+ | Field | Type | Null | Key | Default | Extra | +-+- -+ | id | int (5) | NO | PRI | NULL | name | varchar (10) | NO | | NULL | | +-+-+ 2 rows in set (0.00 sec) mysql > delete from info Query OK, 1 row affected (0.00 sec)

From the server:

Mysql > alter table info modify id int (5) not null;Query OK, 1 row affected (0.02 sec) Records: 1 Duplicates: 0 Warnings: 0mysql > desc info +-+ | Field | Type | Null | Key | Default | Extra | +-+- -+ | id | int (5) | NO | PRI | NULL | name | varchar (10) | NO | | NULL | | +-+-+ 2 rows in set (0.00 sec) mysql > delete from info Query OK, 1 row affected (0.00 sec)

Client: rewriting data

Mysql > insert into info (id,name) values; Query OK, 1 row affected (0.01 sec)

Primary server:

Mysql > select * from info;+----+-+ | id | name | +-+-+ | 1 | zhangsan | +-+-+ 1 row in set (0.00 sec) # you need to review the status record position again at this time, as follows: mysql > show master status +-+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +- -+ | master-bin.000001 | 2955 | +- -+ 1 row in set (0.00 sec)

From the server:

Mysql > change master to master_host='192.168.68.133',master_user='myslave',master_password='123456',master_log_file='master-bin.000001',master_log_pos=2955;ERROR 3021 (HY000): This operation cannot be performed with a running slave io thread; run STOP SLAVE IO_THREAD FOR CHANNEL''first.mysql > STOP SLAVE IO_THREAD FOR CHANNEL''; Query OK, 0 rows affected (0.00 sec) mysql > stop slave Query OK, 0 rows affected, 1 warning (0.00 sec) mysql > change master to master_host='192.168.68.133',master_user='myslave',master_password='123456',master_log_file='master-bin.000001',master_log_pos=2955;Query OK, 0 rows affected, 2 warnings (0.01 sec) mysql > start slave Query OK 0 rows affected (0.00 sec) mysql > show slave status\ gateway * 1. Row * * Slave_IO_State: Waiting for master to send event Master_Host: 192.168.68.133 Master_ User: myslave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000001 Read_Master_Log_Pos: 2955 Relay_Log_File: relay-log-bin.000002 Relay_Log_Pos: 321 Relay_Master_Log_File: master-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 2955 Relay_Log_Space: 526 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id : 1 Master_UUID: 5bb93767-328a-11ea-820a-000c290bd936 Master_Info_File: / usr/local/mysql/data/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log Waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite _ DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec)

Forget it, let's delete all the data from the data tables on the three servers and copy them again; follow the master-slave replication to continue the read separation operation.

Turn off master-slave replication from the server:

Mysql > stop slave;Query OK, 0 rows affected (0.00 sec)

Write different data from the server:

Slave1:

Mysql > insert into info values; Query OK, 1 row affected (0.00 sec) mysql > select * from info;+----+-+ | id | name | +-- +-+ | 1 | zhangsan | | 2 | lisi | +-+ 2 rows in set (0.00 sec)

Slave2:

Mysql > insert into info values; Query OK, 1 row affected (0.00 sec) mysql > select * from info;+----+-+ | id | name | +-- +-+ | 1 | zhangsan | | 3 | wangwu | +-+ 2 rows in set (0.00 sec)

Client:

Mysql > select * from info;+----+-+ | id | name | +-+-+ | 1 | zhangsan | | 2 | lisi | +-+-- + 2 rows in set (0.00 sec) mysql > select * from info +-+ | id | name | +-+-+ | 1 | zhangsan | | 3 | wangwu | +-+-+ 2 rows in set (0.00 sec) read separation summary

MySQL read separation is a data read operation on the slave server of MySQL. Two of them do load balancing, round-robin reading, reduce pressure and improve concurrent access.

About the MySQL master from copy and read-write separation to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report