LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-24-2006, 07:59 AM   #1
mackdav
Member
 
Registered: Feb 2005
Distribution: RHEL, CentOS
Posts: 113

Rep: Reputation: 16
Trying to restore mysql dump, error 1062: Duplicate entry


I have inherited a stone-aged RedHat 8.0 system running mysql 3.23.52 which cannot be upgraded for various reasons I won't go into here. However the powers that be are finally interested in backing this system up, so I have started looking into mysqldump. In the interests of recoverability, I have created a RedHat 9 system running mysql version 3.23.54 which I am now attempting to restore my dump file to.

So. To create my dump, I am doing this:

# mysqldump --opt --all-databases --user="root" -p > all-databases.dump

On the restore system, I do this:

# mysql -u root -p < all-databases.dump

...and it ticks along for a while and finally announces:

ERROR 1062 at line 6005: Duplicate entry '1' for key 1

Looking at line 6005, it says (line numbers added by me):

6004: LOCK TABLES groups WRITE;
6005: INSERT INTO groups VALUES (0,'Administrators'),(1,'Anonymous'),(2,'File Admin'),(3,'Company');

This does not appear to be a TINYINT problem; the table does not appear to be defined with a TINYINT.

I have googled around and the lack of an answer implies I'm doing something trivially incorrect.

One answer I found elswhere suggested that I replace this line

INSERT INTO groups VALUES (0,'Administrators'),(1,'Anonymous'),(2,'File Admin'),(3,'Company');

with

INSERT INTO groups VALUES ('','Administrators'),('','Anonymous'),('','File Admin'),('','Company');

This lets me import the database; however, I still have two questions:

First, when I dump the imported database back out, all my keys are shifted; ie instead of

INSERT INTO groups VALUES (0,'Administrators'),(1,'Anonymous'),(2,'File Admin'),(3,'Company');

...it says:

INSERT INTO groups VALUES (1,'Administrators'),(2,'Anonymous'),(3,'File Admin'),(4,'Company');

Is that going to be a problem if my group keys have all changed by one? Especially since no other tables have changed? (ie this, plus the server version, is the only line that is detected as a change when I diff the original dump and the dump of the restored database).

Secondly, is there some way to make mysqldump export the file in such a way that it will import back in cleanly? It seems wrong to have to mess with the dump file just to make it import again.
 
Old 04-25-2006, 03:02 AM   #2
zeitounator
Member
 
Registered: Aug 2003
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262

Rep: Reputation: 30
The problem is trying to insert a '0' in an auto-increment field... Mysql will automagically transform that to a '1'... leading to a duplicate key when you try to insert the second record. Your solutions:
- Remove the auto-increment from the table definition, insert your records and then alter the table to restore auto-increment on that field
- Change the insert sequence like this:
Code:
INSERT INTO groups VALUES (1,'Anonymous'),(2,'File Admin'),(3,'Company');
INSERT INTO groups VALUES (null, 'Administrator');
UPDATE groups SET idgroup = 0 WHERE groupName = 'Administrator';
 
  


Reply

Tags
mysql, mysqldump


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SuSE PATH value with duplicate entry PAOLO_GRS Linux - Software 5 03-06-2006 04:01 AM
Im getting a mysql_error Duplicate entry? blanderson Linux - Newbie 0 10-17-2003 12:29 PM
mysql dupe entry error, how to avoid? hydro Linux - Software 0 09-20-2003 12:08 PM
Error: Acct: Couldn't insert SQL accounting START record - Duplicate entry '15212' fo ethanchic Linux - Software 0 04-11-2003 10:48 PM
dump/restore moger Linux - Software 4 12-31-2002 04:34 AM


All times are GMT -5. The time now is 01:21 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration