MySQL configuration master-slave server (one master and multiple slaves)

MySQL configuration master-slave server (one master and multiple slaves)

This article mainly introduces the configuration of MySQL master-slave server (one master and multiple slaves). If you are interested, you can learn more about it.

Current Environment
Centos 7.6
MySQL 5.7

Centos 7.6 installation of MySQL 5.7 please refer to: https://www.jb51.net/article/99965.htm

Ideas

insert image description here

insert image description here

Host Configuration

Modify conf

vim /etc/my.cnf

Add the configuration after [mysqld], save and exit

server-id=1
log-bin=master-bin
log-bin-index=master-bin.index

Restart

systemctl restart mysqld.service

# Check the status systemctl status mysqld.service

test

mysql -u root -p
SHOW MASTER STATUS; 

insert image description here

Slave 1 Configuration

Modify conf

vim /etc/my.cnf

Add the configuration after [mysqld], save and exit

server-id=2
relay-log=slave-01-relay-bin
relay-log-index=slave-01-relay-bin.index

Restart

systemctl restart mysqld.service
# Check the status systemctl status mysqld.service

Slave 2 Configuration

Modify conf

vim /etc/my.cnf

Add the configuration after [mysqld], save and exit

server-id=3
relay-log=slave-02-relay-bin
relay-log-index=slave-02-relay-bin.index

Restart

systemctl restart mysqld.service
# Check the status systemctl status mysqld.service

Configuring master-slave relationships

Host Configuration

Log in to the host MySQL console, create a user, authorize and refresh.

mysql -u root -p

CREATE USER 'repl'@'%' IDENTIFIED BY 'Mysql57*';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'Mysql57*';
flush privileges;

insert image description here

Slave Configuration

mysql -u root -p

# My host IP here is 192.168.1.8
change master to master_host='192.168.1.8',master_port=3306,master_user='repl',master_password='Mysql57*',master_log_file='master-bin.000001',master_log_pos=0;

start slave;
#Stop master-slave synchronization#stop slave;
# \G means line break to view show slave status \G; 

If you check the master-slave status, you will see the message "The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work." Please refer to the FAQ

insert image description here

Test data synchronization

Here the author uses the visualization tool Navicat, readers can also use other tools, just a simple test.

Add a new library test-for-repl in the master library, and check whether there is a new library in slave libraries 01 and 02

Add a new table test-create-table in the master library test-for-repl to check whether there is a table in the slave library 01 and 02. Add a new table test-create-table in the master library test-for-repl to check whether there is data in the slave library 01 and 02.

insert image description here

Frequently asked questions

The slave machine checks the master-slave synchronization status show slave status \G; and reports an error

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

insert image description here

reason

Here, the author used VMware software to create a virtual machine to install Centos7.6 + MySQL5.7, and then used the virtual machine to clone two other virtual machines as slave machines, resulting in the same UUID being generated after MySQL on the three virtual machines is started.

Solution

Find the UUID of MySQL, modify one character, restart the service, then log in to the MySQL console and enable the master-slave

find / -name 'auto.cnf'
vim /var/lib/mysql/auto.cnf
systemctl restart mysqld.service
mysql -u root -p
start slave;
# \G means line break to view show slave status \G; 

This is the end of this article about configuring MySQL master-slave server (one master and multiple slaves). For more relevant MySQL master-slave server content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of MySQL cluster: one master and multiple slaves architecture implementation
  • Implementation steps of Mysql one master and multiple slaves deployment

<<:  How to implement blank space in Taobao with CSS3

>>:  html option disable select select disable option example

Recommend

When the interviewer asked the difference between char and varchar in mysql

Table of contents Difference between char and var...

Example verification MySQL | update field with the same value will record binlog

1. Introduction A few days ago, a development col...

A brief discussion on how Tomcat breaks the parent delegation mechanism

Table of contents JVM Class Loader Tomcat class l...

What is this in JavaScript point by point series

Understand this Perhaps you have seen this in oth...

Share 13 basic syntax of Typescript

Table of contents 1. What is Ts 2. Basic Grammar ...

Issues with Rancher deployment and importing K8S clusters

Rancher deployment can have three architectures: ...

Modify the boot time of grub in ubuntu

The online search to modify the grub startup time...

CSS3 achieves various border effects

Translucent border Result: Implementation code: &...

Why MySQL does not recommend using null columns with default values

The answer you often hear is that using a NULL va...

Docker enables seamless calling of shell commands between container and host

As shown below: nsenter -t 1 -m -u -n -i sh -c &q...

Simple example of adding and removing HTML nodes

Simple example of adding and removing HTML nodes ...

MySQL 5.7.18 installation and configuration tutorial under Windows

This article shares the installation and configur...

How to connect Navicat to the docker database on the server

Start the mysql container in docekr Use command: ...

How to install ionCube extension using pagoda

1. First install the pagoda Installation requirem...