Set a different ID,
Main MySQL server IP 192.168.13.177 Mysql server IP 192.168.13.187
Implement two MySQL backup at the same time
First of all, the two servers can communicate with each other, setting mysql can be remotely connected
1. Switch the root account in the main MySQL (IP192.168.13.177)
2, log in to mysql execution command MySQL -UROOT -PROOT
3. Execute the following command
grant replication slave on . to ‘root’@‘192.168.13.187’ identified by ‘root’;
flush privileges;
4. Set the master mysql my.cnf file. You need to copy the following code in and modify the data you want to synchronize
binlog-DO-DB = WeChat # Database that needs to be recorded in the log. If there are multiple databases, you can use a comma to separate, or use multiple BINLOG-DO-DB options
binlog-impnore-db = MySQL # Database that does not need to be recorded in the log. If there are multiple databases, you can use a comma to separate, or use multiple BINLOG-DO-DB options
Replicate-DO-DB = WeChat # need to be synchronized database. If there are multiple databases to separate with a comma, or use multiple replicate-DO-DB options
replicate-impnore-db = mysql, information_schema # does not need synchronous database. If there are multiple databases to separate with comma, or use multiple replicate-impnore-db options
# synchronous parameters:
server-id=1
log_bin = /var/log/mysql/mysql-bin
# 15 15 15 15 15 15 will receive the writing information of another master on any master
log-slave-updates
sync_binlog=1
auto_increment_offset=1
auto_increment_increment=2
SLAVE-SKIP-ERRORS = All # filter out some errors without any big problems
5. Restart MySQL service
service mysqld restart
6. Log in mysql command MySQL -UROOT -PROOT
execute the brush log command Flush Logs;
View log
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 106
Binlog_Do_DB: wechat
Binlog_Ignore_DB:
1 row in set (0.00 sec)
File: MySQL-BIN.000001, Position: 106 is provided to the backup mysql
7. Log in to backup MySQL (IP192.168.13.187) Switching root account
8. Log in mysql executing command MySQL -UROOT -PROOT
9. Execute the following command
grant replication slave on . to ‘root’@‘192.168.17.157’ identified by ‘root’;
flush privileges;
10. Set the owner mysql my.cnf file. You need to copy the following code into it, modify the data you want to synchronize
mysql prepare my.cnf file
server-id =
binlog-DO-DB = WeChat # Database that needs to record binary logs. If there are multiple databases, you can use a comma to separate,
binlog-impnore-db = MySQL # Database that does not need to record the logging log. If there are multiple databases, you can use a comma to separate
# Need to synchronize databases
replicate-do-db=wechat
# need to be synchronized database. If there are multiple databases, you can use a comma to separate, or use multiple BINLOG-DO-DB options
replicate-impnore-db = mysql, information_schema # does not require synchronous database. Multiple databases can be separated by comma
# synchronous parameters:
log-bin =mysql-bin
# 3 3 3 3 3 3 will receive the writing information of another master on any master
log-slave-updates
sync_binlog=1
auto_increment_offset=2
auto_increment_increment=2
SLAVE-SKIP-ERRORS = All # filter some errors without any big problems
11. Restart MySQL service
service mysqld restart
12, log in to mysql command MySQL -UROOT -PROOT
execute stop slave;
CHANGE MASTER TO
MASTER_HOST=‘192.168.17.157’,
MASTER_USER=‘root’,
MASTER_PASSWORD=‘root’,
MASTER_LOG_FILE=‘mysql-bin.000013’,
MASTER_LOG_POS=106;
execute start slave;
execution
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.13.177
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 106
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000007
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: wechat
Replicate_Ignore_DB: mysql,information_schema
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 106
Relay_Log_Space: 407
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
Just see two yes
Then do the main MySQL data to add a data test to see if there is data to back up the MySQL server (successful, the next step)
13. View the log situation in the backup server
execute the brush log command Flush Logs;
View log
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000005
Position: 106
Binlog_Do_DB: wechat
Binlog_Ignore_DB:
1 row in set (0.00 sec)
File: MySQL-BIN.000005, POSITION: 106 is provided to the main mysql for use
14. Switch the main MySQL server
execute stop slave;
mysql> CHANGE MASTER TO
-> MASTER_HOST=‘192.168.13.187’,
-> MASTER_USER=‘root’,
-> MASTER_PASSWORD=‘root’,
-> MASTER_LOG_FILE=‘mysql-bin.000005’,
-> MASTER_LOG_POS=106;
Query OK, 0 rows affected (0.10 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.13.187
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000005
Read_Master_Log_Pos: 106
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: wechat
Replicate_Ignore_DB: mysql,information_schema
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 106
Relay_Log_Space: 407
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
and then test!