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, 146 hits)