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

How to set up master-slave synchronization in MYSQL database

PHPz
Release: 2023-05-26 14:04:06
forward
4276 people have browsed it

1. Configure the master database

Master master: 192.168.1.132

Slave: 192.168.1.133

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

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
Copy after login

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
Copy after login

4) Restart the service:

service mysqld restart
Copy after login

5) Enter the following statement

 show master status;
Copy after login

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
Copy after login

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
Copy after login

(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
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template