Database resyncronization depends on what went wrong but the steps below will most likely solve most issues.
Run these commands on the slave database
- STOP SLAVE; # stop the Slave I/O threads
- RESET SLAVE; # forget about all the relay log files
Then go to the master database and run these
- RESET MASTER; # reset the bin log counter and wipe out bin log files
- FLUSH TABLES WITH READ LOCK; # flush buffers and LOCK tables
- show master status\G
Note what the show master status command returns. You’ll need to know the file name and the position.
You can do one of two things here, make a dump of the entire master database (in which case I suggest you follow this)
or you can just update the tables.
Usually we just need to update the tables so release the lock on the master database tables (UNLOCK TABLES;) and then run this command on the slave database (download maatkit tools here),
- cd ~/maatkit-5014/bin && sudo ./mk-table-sync –[print][execute] u=[user],p=[pass],h=[master_host_name] –databases [database_name(s)] localhost
I suggest you run –print before you run –execute. If you run –execute first, you have no idea what just happened. –print will let you know what it’ll do without actually doing anything.
Back to the slave database mysql client, issue these commands,
- CHANGE MASTER TO MASTER_LOG_FILE='[file name from show master status command]’, MASTER_LOG_POS=[pos];
- SLAVE START;
Run this command,
- show slave status\G
And check that these aren’t NO or NULL,
If things aren’t back to normal, follow the instructions on this website.