问题
I dropped all tables from a database then restore(import) a backup. Afterwards I am getting error #1062 - Duplicate entry '1' for key 1
.
Should i repeat the process. Or something else? Why this error is coming?
回答1:
When you export your sql from php admin
Select "custom" as export method"
then, instead of 'insert', choose "update"
This will perform update-statements and prevent duplicated inserts.
回答2:
This indicates that you have a UNIQUE or PRIMARY index on a table, and there is a duplicate value on one of the values that will be inserted into one of these indexes.
You'll need to look at which particular operation caused this error to find out which table and which row it was trying to write. Hopefully, phpMyAdmin should tell you which row of data caused the problem, shouldn't it?
One guess is that you're importing data that duplicates some data already in a table, ie you may not have removed the existing data like you thought you had. But it could be any number of things.
回答3:
From the sounds if it, the dump has a duplicate entry inside the queries it holds.
Although this shouldn't happen, it happened to me in the past. In order to solve this, I would advise two options:
- Manually remove the
ADD UNIQUE INDEX
and/orPRIMARY KEY
at the start of each table dump. Then create a same structure table, add the missing index, andINSERT IGNORE INTO new_tbl (SELECT * FROM tbl)
- Adding
INSERT IGNORE
for the insert statement in the log
回答4:
To fix this, when you want to export DB you can try to untick "Do not use AUTO_INCREMENT for zero values" under "Format-Specific Options:" , see image below :
来源:https://stackoverflow.com/questions/3278470/phpmyadmin-error-1062-duplicate-entry-1-for-key-1