MYSQL one master and multiple slaves

MYSQL one master and multiple slaves

1. Prepare 4 mysql service port numbers as 3307, 3308, 3309, 3310 respectively
2. Modify the my.cnf file of the four mysql.
I choose 3307 as the master server, and the other three are
the my.cnf of the slave server 3307 and add binary Log and service id

log-bin=mysql-bin
server-id=3307
Insert picture description here


Add service id to my.cnf of 3308

server-id=3308

Add service id to my.cnf of 3309

server-id=3309

3310 add service id to my.cnf

server-id=3310

3. Start 4 mysql
startup commands

./mysqld_safe &

Enter the main server to view the status and offset of the main server

 ./mysql -uroot -p123456 -P3307 -h127.0.0.1
 show master status
Insert picture description here


4. Create a user account for communication between slave and master

GRANT replication slave ON *.* TO 'liu'@'%' IDENTIFIED BY '123456';

Check the offset again and find that the offset has changed.

Insert picture description here


Reset the offset

reset master
Insert picture description here


5. Respectively enter the slave database to set the slave node
Set the slave node

change master to  master_host="47.110.157.82",master_port=3307,
master_user="liu",master_password="123456",
master_log_file="mysql-bin.000001",master_log_pos=154;

Start slave node

start slave;
Insert picture description here


Insert picture description here


Insert picture description here


View the slave node in the slave database

show slave status \G;

success

Insert picture description here