Analysis of Difficulties in Hot Standby of MySQL Database

Analysis of Difficulties in Hot Standby of MySQL Database

I have previously introduced to you the configuration method of MySQL database dual-machine hot standby. Friends who are interested can refer to it. In this section, we focus on summarizing and analyzing the important links and areas that need attention.

I. Introduction

mysql version: 5.7.20

The first main server ip:192.168.71.139

The second main server ip:192.168.71.141

2. Configuration

The first primary server 192.168.71.139

1: Modify the /etc/mysql/my.cnf file. Note that # here is a comment. Do not write it into the configuration file.

server-id = 141 #Server id, cannot be repeated, it is recommended to use the last three digits of the IP.
log-bin = mysql-bin
binlog-ignore-db = mysql,information_schema #Ignore the library that writes binlog logs
auto-increment-increment = 2 #Field change increment value
auto-increment-offset = 1 #The initial field ID is 1
slave-skip-errors = all #Ignore all replication errors

2: Log in to MySQL and create an account that allows other servers to replicate

GRANT REPLICATION SLAVE ON *.* to 'mysql account'@'%' identified by 'password';

3: Use show master status to query the status

The second primary server is 192.168.71.139

1: Modify the /etc/mysql/my.cnf file, where server-id = 139, and the rest remain unchanged.

Use show master status to query the status

At this point, you need to restart mysql on both servers

Execute synchronization statements at 192.168.71.141

The master_log_file value comes from the 139 server, the File field after executing show master status

The master_log_file value comes from the 139 server, the Position field after executing show master status
change master to master_host='192.168.71.139',master_user='master2',master_password='123456',master_log_file='mysql-bin.000002',master_log_pos=154;

Execute synchronization statements at 192.168.71.139

The master_log_file value comes from the 141 server, the File field after executing show master status

The master_log_file value comes from the 141 server, the Position field after executing show master status

change master to master_host='192.168.71.141',master_user='master1',master_password='123456',master_log_file='mysql-bin.000002', master_log_pos=154;

This is the end of the configuration. Restart MySQL, log in to MySQL, and use show slave status\G to check the configuration status. It is found that Slave_IO cannot be started and the following error occurs.

The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.

The log shows that the master and slave uuids are duplicated. Because the two servers are cloned, you need to modify /var/lib/mysql/auto.cnf

Here I only changed the last letter, because if I changed too much, I couldn't start mysql. After the modification is completed, restart MySQL, log in to MySQL and execute show slave status\G, as shown below

Three: Test

Execute the following sql on any server

create table tab141(id int primary key);

create table tab139(id int primary key);

Execute the following sql on the 139 server

insert into tab139 values(1);

Execute the following sql on the 141 server

insert into tab141 values(2);

The results are as follows:

If you have any questions, please feel free to discuss in the comment area below.

You may also be interested in:
  • MySQL backup and recovery hot standby (3)
  • Detailed steps to implement MySQL hot backup under Linux system (MySQL master-slave replication)
  • Configuration method of Mysql database dual-machine hot standby
  • Implementation steps of mysql dual-machine hot backup

<<:  Three networking methods and principles of VMware virtual machines (summary)

>>:  Vue implements video upload function

Recommend

Does Mysql ALTER TABLE lock the table when adding fields?

Table of contents Before MySQL 5.6 After MySQL 5....

MySQL5.7 parallel replication principle and implementation

Anyone who has a little knowledge of data operati...

Implementation of Nginx configuration of multi-port and multi-domain name access

To deploy multiple sites on a server, you need to...

MySQL 8.0.22 installation and configuration graphic tutorial

MySQL8.0.22 installation and configuration (super...

VMware12.0 installation Ubuntu14.04 LTS tutorial

I have installed various images under virtual mac...

Tutorial on installing MySQL 5.6 on CentOS 6.5

1. Download the RPM package corresponding to Linu...

Mysql sets boolean type operations

Mysql sets boolean type 1. Tinyint type We create...

Mac VMware Fusion CentOS7 configuration static IP tutorial diagram

Table of contents Install CentOS7 Configuring Sta...

How to restore a single database or table in MySQL and possible pitfalls

Preface: The most commonly used MySQL logical bac...

Detailed analysis of the principles and usage of MySQL views

Preface: In MySQL, views are probably one of the ...

js to upload pictures to the server

This article example shares the specific code of ...

A Brief Analysis of the Differences between “:=” and “=” in MySQL

= Only when setting and updating does it have the...