MySQL Error: 1062 'Duplicate entry' Error

The all too common MySQL ‘Duplicate entry’ Error.

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: master-mysql.local
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.004768
          Read_Master_Log_Pos: 1022786917
               Relay_Log_File: relay-bin.001728
                Relay_Log_Pos: 929659721
        Relay_Master_Log_File: mysql-bin.004768
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          Replicate_Ignore_DB: information_schema,mysql
           Replicate_Do_Table: 
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 1062
                   Last_Error: Error 'Duplicate entry 'xyz' for key 'PRIMARY'' on query. Default database: 'db'. Query: 'INSERT INTO  data  (   id,   version ) VALUES  (279598012, 5)'
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 929659575
              Relay_Log_Space: 1022787256
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 1062
               Last_SQL_Error:Error 'Duplicate entry 'xyz' for key 'PRIMARY'' on query. Default database: 'db'. Query: 'INSERT INTO  data  (   id,   version ) VALUES  (279598012, 5)'
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 10147115
1 row in set (0.00 sec)


The easy way to deal with this is to verify this it is a replication entry and running the following command.

mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;

However, if you have what seems to be a large number of duplicate entry error and don’t feel like skipping the entries one by one or you just don’t want replication to stop for this error. You can add the following to the /etc/my.cnf

slave-skip-errors = 1062

And restart the MySQL services. This will skip all the Duplicate entry errors until it’s removed and the MySQL is restarted.

Keep in mind, that this error can indicate other issues with the MySQL service or system, before skipping the error completely.

15 responses to “MySQL Error: 1062 'Duplicate entry' Error”

  1. Appliance Repair Manual Avatar

    I am really loving the theme/design of your weblog. Do you ever run into any browser compatibility issues? A few of my blog readers have complained about my site not working correctly in Explorer but looks great in Firefox. Do you have any advice to help fix this issue? http://www.kayswell.com

  2. Dennis Marks Avatar

    you are truly a just right webmaster The site loading speed is incredible It kind of feels that youre doing any distinctive trick In addition The contents are masterwork you have done a great activity in this matter

  3. Maida Little Avatar

    Hi my family member I want to say that this post is awesome nice written and come with approximately all significant infos I would like to peer extra posts like this

  4. Duncan Green Avatar

    I just wanted to express my gratitude for the valuable insights you provide through your blog. Your expertise shines through in every word, and I’m grateful for the opportunity to learn from you.

  5. Hollie Boyer Avatar

    Your blog is a testament to your dedication to your craft. Your commitment to excellence is evident in every aspect of your writing. Thank you for being such a positive influence in the online community.

  6. Lazaro Quitzon Avatar

    helloI like your writing very so much proportion we keep up a correspondence extra approximately your post on AOL I need an expert in this space to unravel my problem May be that is you Taking a look forward to see you

  7. Beyoğlu walking tour Avatar

    Beyoğlu walking tour Fun, informative, and well-paced. https://parathajoint.com/?p=117911

  8. Hairstyles VIP Avatar

    Thanks for your help and for writing this post. It’s been great. http://www.hairstylesvip.com

  9. Hairstyles VIP Avatar

    Hi there, its fastidious article concerning media print, we all be aware of media is a great source of data. http://www.hairstylesvip.com

  10. Alexandrine Johnson Avatar

    Your blog is a treasure trove of valuable insights and thought-provoking commentary. Your dedication to your craft is evident in every word you write. Keep up the fantastic work!

  11. Wilburn Olson Avatar

    Magnificent beat I would like to apprentice while you amend your site how can i subscribe for a blog web site The account helped me a acceptable deal I had been a little bit acquainted of this your broadcast offered bright clear idea

  12. zxpfwnsxrw Avatar

    zkjxxikoofsoihyexktznwfrfiwoos

  13. Bryce Leannon Avatar

    Wow wonderful blog layout How long have you been blogging for you make blogging look easy The overall look of your site is great as well as the content

  14. Appliance Repair Manual Avatar

    Wow, marvelous weblog structure! How long have you ever been running a blog for? you make running a blog glance easy. The overall look of your web site is wonderful, as smartly as the content material! http://www.kayswell.com

  15. Demetris Konopelski Avatar

    I have read some excellent stuff here Definitely value bookmarking for revisiting I wonder how much effort you put to make the sort of excellent informative website

Leave a Reply