MySQL bidirectional synchronization practices
MySQL Master/Slave server (replication) settings: 1. First, create an account for the slave server on the master server. 2. Step 1
If the applied user name and password can be used to access the master database, the user is successfully created. (Dual-machine Hot Standby is created on two machines respectively
Replication account ).
Assume that the IP addresses of the two machines are as follows:
Servera: 192.168.1.103 (SA)
Serverb: 192.168.1.108 (SB)
Back up a database and restore it to another machine. perform the following operations:
1. Create an account for replication on the two machines. The command is as follows:
Mysql> grant replication slave on *. * To 'username '@ 'host' identified by 'Password ';
Then perform tests on SA and Sb respectively.
Mysql-hserverip-ureplicationname-preplicationpassword
If the operation succeeds, the account is valid. Otherwise, you must add a new user. (Firewall settings)
Example
(SA)
Mysql> grant replication slave on *. * To 'backup '@ '192. 168.1.108 'identified by '123'
(SB)
Mysql> grant replication slave on *. * To 'backup '@ '192. 168.1.103 'identified by '123'
(SB)
Mysql-h192.168.1.103-ubackup-p123456
Stop the MySQL service of the two machines. Perform the following operations:
2. Edit the my. ini file of SA and add the following information under mysqld:
Server-id = 1 (master server ID, which cannot be repeated)
BINLOG-do-DB = dbfood (database to be copied)
Log-bin = "C:/mysqlbak/log" (where the log file is stored, the final parameter indicates the log file name, and replication is based on log)
Edit the my. ini file of Sb,
Server-id = 2 (master server ID, which cannot be repeated)
Restart the MySQL service of SA and sb
(SA)
Mysql> show Master Status \ G
Position: 107
File: dbfood-bin.000001
(SB)
Run:
Mysql> change master to master_host = '192. 168.0.103 ', master_user = 'backup', master_password = '2016 ',
Master_log_file = 'dbfood-bin.000001 ', master_log_pos = 0;
(SB)
Restart MySQL Service
Mysql> Start slave;