Fixing MySQL Replication with duplicate key error

Today our MySQL Master tracking db went down (due to host server crashing) which consequently screwed up the slave. Here are the steps I took to fix it.
Firstly, check the slave status with:

 show slave status\G;

If the slave is reporting something like ”Last_Error: Error Duplicate entry replication”, this can be fixed by the following:

 stop slave;
 set global sql_slave_skip_counter=1;
 start slave;
 show slave status\G;

It will take some time after issuing those commands for the slave to rebuild itself from the master, but you can check the progress by querying the db to see what record we are up to, for example:

 connect trackdb;
 SELECT * FROM `track` WHERE 1 ORDER BY id DESC LIMIT 10;

Leave a Reply

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