Skip duplicate entries in a slave with MySql

By jbayer - Last updated: Tuesday, January 10, 2012 - Save & Share - One Comment

While setting up some replication, I got a duplicate key error on the slave.

Since I knew it wasn’t a problem, I just wanted to bypass it and continue with the replication.

The attached script will do that.

Briefly, it checks the slave status and if there is a Duplicate entry error, then it stops the slave, does a “set global sql_slave_skip_counter=1”, and then restarts the slave.

It loops once every 7 seconds, and can either be an infinite loop or a limited number.  I had to run this 4 or 5 times before the errors were skipped.

Other than the number of seconds to sleep, nothing is hard-coded;   you have to enter the db user and password.  It is set so that if you want to, it can be run from a cron.

 

  skipdup.zip (587 bytes, 149 hits)

Posted in Administration, Database • • Top Of Page
655 views

One Response to “Skip duplicate entries in a slave with MySql”

Comment from Baron Schwartz
Time February 21, 2012 at 1:57 pm

pt-slave-restart might be another option for this.

Write a comment

asd