Home  >  Article  >  Database  >  How to set up master-slave synchronization in MYSQL database

How to set up master-slave synchronization in MYSQL database

PHPz
PHPzforward
2023-05-26 14:04:064222browse

1. Configure the master database

Master master: 192.168.1.132

Slave: 192.168.1.133

1)授权给从数据库
GRANT REPLICATION SLAVE ON *.* to 'repl'@'192.168.1.132' identified by 'test123456';
FLUSH PRIVILEGES;

How to set up master-slave synchronization in MYSQL database

2) Modify the main library configuration file, enable binlog, and set server-id. Every time you modify the configuration file, you must restart the mysql service to take effect.

vim /etc/my.cnf

How to set up master-slave synchronization in MYSQL database

server-id: master The ID number of the terminal;

log-bin: the synchronized log path and file name. This directory must be written by mysql with permission;

binlog-do-db: the name of the database to be synchronized

3) Authorization

chown mysql:mysql -R /usr/local/mysql_data

4) Restart the service:

service mysqld restart

5) Enter the following statement

 show master status;

How to set up master-slave synchronization in MYSQL database

2, Configure the slave database

1) Set the slave database configuration

vi /etc/my.cnf

server-id

replicate-do-db=world

How to set up master-slave synchronization in MYSQL database

2) Add the address, port number, synchronization user, password, log file, and file starting position of the main database.

How to set up master-slave synchronization in MYSQL database

3) Delete auto.cnf

 cd /usr/local/mysql_data/

 rm  -rf  auto.cnf

(If you don’t delete it, the synchronization will fail)

4) Start the slave database master-slave

How to set up master-slave synchronization in MYSQL database

show slave status

How to set up master-slave synchronization in MYSQL database

5) Insert data into the master data, and the slave data is the synchronized data.

The above is the detailed content of How to set up master-slave synchronization in MYSQL database. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete