Things should be as simple as possible, but not simpler. – Albert Einstein

Resyncing Broken MySQL Replication

These instructions apply to simple case of one slave replicating from one master.
  1. Prepare the slave
  2. Prepare the master, copy databases and restart master
  3. Restart Replication Slave

Prepare the slave

SSH into the slave server.
Log into MySQL on the slave as root

mysql>STOP SLAVE;
mysql>RESET SLAVE;
mysql> exit;

Now exit and shutdown slave

$ mysqladmin shutdown -u root -p

Delete the databases on slave (DANGER … this deletes ALL databases on slave)
$ cd /usr/local/mysql/
$ sudo rm -r data

Prepare the master, copy databases and restart master

SSH into the master as root
log into mysql as root

Check users and kick them all off if more than yourself is connected
mysql> show processlist;

Reset the Master
mysql> RESET MASTER;

exit and shutdown immediately

$ mysqladmin shutdown -p
Now copy all the data from this master to the slave (may take a while)

# cd /usr/local/mysql
# scp -r data root@slavehost:/usr/local/mysql

Note: If you have a really huge amount of data and you have the drive space, it may be faster to make a local copy of the data directory on the master which can be then copied to the slave after you have restarted the master.

When copying is done, restart the master

$ sudo echo
$ sudo mysqld_safe &

Log into master and make sure it is logging.

mysql> show master status\G

*************************** 1. row ***************************

File: binary-log.002
Position: 280
Binlog_do_db:
Binlog_ignore_db:

1 row in set (0.00 sec)

Make sure Position is increasing if insert and update activity is taking place on master.

Now you can breathe for a while!

Restart Replication Slave

Log into slave server and fix privileges on the data folder

$ cd /usr/local/mysql
$ sudo chown -R mysql. data

Restart server

$ sudo echo
$ sudo mysqld_safe &

Log into mysql as root

mysql> SHOW SLAVE STATUS\G;

Verify that it is replicating and you are done.

Great References:

Linux System Admins Blog

MySQL: How do you set up master-slave replication in MySQL?

Resyncing Broken MySQL Replication

How to make MySQL replication reliable

http://www.maatkit.org/

Out with cluster, hello replication

HOWTO Mysql Master Slave Resync

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Rss Feed Tweeter button Facebook button