How to prevent duplicate entry error in MySQL

Sometimes, errors should be ignored because they are not necessary at all. In MySQL especially for replication, the general architecture is to have a host for write and other hosts for read. As a result, response time of the whole system should be more scalable. If something goes wrong at the master node where all write operations must be performed, the error may propagate to other replications. One of common error oftenly occurs during replication is duplicate entry. It is possible to prevent this error which may lead the replication to stop.

This problem was reported for so long and it it supposed to be fixed already. However, I still got them sometimes. The solution is to specify slave-skip-erros at client side as follows.

[mysqld]
slave-skip-errors = 1062

1062 means to duplicate entry error. For more information, read below links.

Tags: ,

Yes, that's very useful for

Yes, that's very useful for a lot of things. Thanks.

ขอบคุณครั

ขอบคุณครับ จะลองไปทำดู

Great Solution!

We implemented a master/slave MySQL solution a few months ago for our site at http://www.blogpatrol.com and encountered the "duplicate entry error" for the first time today. After cleaning up our database, we implemented your solution to prevent the error in the future. We've credited your solution on our blog at http://thepatrolblog.blogspot.com/2007/07/database-down.html Thanks for sharing this tip!

Great tip, cheers.

Great tip, cheers.

Site has errors

Your site is getting mysql errors. Plus, there is no email contact readily available for me to send this message to, so I had to put up a posting in hope that someone would come and fix this site. No Contact Us information is a usability issue that should be corrected also.

it's work fine in your

it's work fine in your opinion

skip errors?

you said that when you put that small piece of configuration the mysql config file... it will skip the error but it might lead the replication to stop. so it means that the slave will not function anymore? or it will just skip the specific row where the error occurs

Post new comment