MySQL Forums
Forum List  »  Backup

Re: mysqldump restore triggers error 1062
Posted by: Solomon Rutzky
Date: April 23, 2006 02:54PM

Hello David. I just spent many frustrating hours dealing with this stupid issue and finally got it so I felt obligated to sign up for these forums just so that this can be documented. The whole trick / issue revolves around the value of 0 (zero) in your first record (same thing I had). When it sees the 0 it creates a new auto_increment value of 1 and so on the next record (being the real value of 1) it already existed. So, if you are lucky enough to be running version 4.1.1 or higher (unlike myself), you can go with what I found in the documentation:

http://dev.mysql.com/doc/refman/4.1/en/server-sql-mode.html

NO_AUTO_VALUE_ON_ZERO

NO_AUTO_VALUE_ON_ZERO affects handling of AUTO_INCREMENT columns. Normally, you generate the next sequence number for the column by inserting either NULL or 0 into it. NO_AUTO_VALUE_ON_ZERO suppresses this behavior for 0 so that only NULL generates the next sequence number. (New in MySQL 4.1.1)

This mode can be useful if 0 has been stored in a table's AUTO_INCREMENT column. (Storing 0 is not a recommended practice, by the way.) For example, if you dump the table with mysqldump and then reload it, MySQL normally generates new sequence numbers when it encounters the 0 values, resulting in a table with contents different from the one that was dumped. Enabling NO_AUTO_VALUE_ON_ZERO before reloading the dump file solves this problem. As of MySQL 4.1.1, mysqldump automatically includes a statement in the dump output that enables NO_AUTO_VALUE_ON_ZERO, to avoid this problem..

(this is also page #281 in the printed manual [page 303 in the PDF])


Since I am running version 3.23.does_it_matter I had to edit the SQL dump file and change the 0 value to -1. Once it loaded, I did an UPDATE on the table and changed the ID value to 0 WHERE it was -1. For me this is a one-time import but you can always add the UPDATE statement just past the INSERT for that table or at the end of the file so it will cleanly import.

Good luck,
Solomon....

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: mysqldump restore triggers error 1062
4621
April 23, 2006 02:54PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.