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;
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
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;
1) Set the slave database configuration
vi /etc/my.cnf
server-id
replicate-do-db=world
2) Add the address, port number, synchronization user, password, log file, and file starting position of the main 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
show slave status
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!