Thursday, October 24, 2013

Reset MySQL slave when it is out of sync

2019/01/24:
Fix bin-log when the log files are missing:
https://www.redips.net/mysql/replication-slave-relay-log-corrupted/

Slave side:
# stop all slaves before resetting the master
(mysql) STOP SLAVE;

Master side:
# set the master database to read-only
(mysql) FLUSH TABLES WITH READ LOCK;

# backup the current database
(bash) mysqldump -u root -p -databases db1 db2 | bzip2 > /tmp/bak.sql.bz

# reset the binary logs
(mysql) RESET MASTER;

Slave side:
(bash) scp -r ericpony@XXX.XXX.XXX.XXX:/tmp/bak.sql.bz /tmp

# load the current database from master
(mysql) SOURCE /tmp/bak.sql.bz;

# reset the binary logs
(mysql) RESET SLAVE;

# restart slave
(mysql) START SLAVE;

Master side:
# unlock the master database
(mysql) UNLOCK TABLES;

Slave side:
# check if everything is ok
(mysql) SHOW SLAVE STATUS \G

Reference

http://www.cnblogs.com/sunyuxun/archive/2012/09/13/2683338.html

No comments:

Post a Comment