Database

Skip Duplicate Replication Error in MySQL

Duplicate-replication-error
mm
Written by Santosh Prasad

MySQL replication get stopped whenever “Duplicate entry” error comes. You can fix this issue to skip such error but it is not recommended, as long as you know really well what are those queries and why they are failing.

In this article I will show you how you can skip these type of error in MySQL.

Skip One Query

You can skip just one query that is hanging the slave using below command.

mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;

There may be situations where you will need to skip more queries. For instance you should need to skip all duplicate error you might be getting:

"1062 | Error 'Duplicate entry 'xyz' for key 1' on query. Default database: 'db'. Query: 'INSERT INTO ..."

Skip All Queries

If you are skipping these queries make sure this will not bring your slave inconsistent. You can add below line into your my.cnf file to skip all queries.

slave-skip-errors = 1062

As mention above I have skipped all 1062 type of error. You can skip also other type of error but again don’t do this unless you understand very well what those queries are and what impact they have on your data.

slave-skip-errors=[err_code1,err_code2,...|all]

You can find all error from here.

Thank you! for visiting Look Linux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment