How to re-sync the Mysql DB if Master and slave have different database incase of Mysql replication?

前端 未结 14 987
小蘑菇
小蘑菇 2020-11-29 14:20

Mysql Server1 is running as MASTER.
Mysql Server2 is running as SLAVE.

Now DB replication is happeni

14条回答
  •  悲&欢浪女
    2020-11-29 14:48

    I am very late to this question, however I did encounter this problem and, after much searching, I found this information from Bryan Kennedy: http://plusbryan.com/mysql-replication-without-downtime

    On Master take a backup like this:
    mysqldump --skip-lock-tables --single-transaction --flush-logs --hex-blob --master-data=2 -A > ~/dump.sql

    Now, examine the head of the file and jot down the values for MASTER_LOG_FILE and MASTER_LOG_POS. You will need them later: head dump.sql -n80 | grep "MASTER_LOG"

    Copy the "dump.sql" file over to Slave and restore it: mysql -u mysql-user -p < ~/dump.sql

    Connect to Slave mysql and run a command like this: CHANGE MASTER TO MASTER_HOST='master-server-ip', MASTER_USER='replication-user', MASTER_PASSWORD='slave-server-password', MASTER_LOG_FILE='value from above', MASTER_LOG_POS=value from above; START SLAVE;

    To check the progress of Slave: SHOW SLAVE STATUS;

    If all is well, Last_Error will be blank, and Slave_IO_State will report “Waiting for master to send event”. Look for Seconds_Behind_Master which indicates how far behind it is. YMMV. :)

提交回复
热议问题