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

Analysis of MySQL latency issues and data flushing strategy process

Table of contents 1. MySQL replication process 2....

How to manage large file uploads and breakpoint resume based on js

Table of contents Preface Front-end structure Bac...

Detailed explanation of CSS elastic box flex-grow, flex-shrink, flex-basis

The functions of the three attributes flex-grow, ...

The current better way to make select list all options when selected/focused

During development, I encountered such a requireme...

Complete steps to install MySQL 8.0.x on Linux

MySQL Introduction to MySQL MySQL was originally ...

Detailed tutorial on installing Python 3.8.1 on Linux

This example takes the installation of Python 3.8...

How to customize an EventEmitter in node.js

Table of contents Preface 1. What is 2. How to us...

Detailed process of installing Presto and connecting Hive in Docker

1. Introduction Presto is an open source distribu...

Deep understanding of the use of ::before/:before and ::after/:after

Part 1: Basics 1. Unlike pseudo-classes such as :...

Vue achieves seamless carousel effect (marquee)

This article example shares the specific code of ...

Summary of MySQL's commonly used database and table sharding solutions

Table of contents 1. Database bottleneck 2. Sub-l...