phpmyadmin 错误“#1062 - 重复条目“1”对于钥匙 1”
我从数据库中删除了所有表,然后恢复(导入)备份。之后我收到错误 #1062 - 键 1 的重复条目“1”
。
我应该重复这个过程吗?或者其他什么?为什么会出现这个错误?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您从 php admin 导出 sql 时
选择“自定义”作为导出方法"
然后,选择“更新”而不是“插入”,
这将执行更新语句并防止重复插入。
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.
这表明您在表上有 UNIQUE 或 PRIMARY 索引,并且将插入到这些索引之一的值之一上存在重复值。
您需要查看哪个特定操作导致了此错误,以找出它试图写入哪个表和哪一行。希望 phpMyAdmin 应该告诉您哪一行数据导致了问题,不是吗?
一种猜测是您正在导入的数据与表中已有的某些数据重复,即您可能没有像您想象的那样删除现有数据。但它可以是任意数量的事情。
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.
从声音来看,转储在其保存的查询中有一个重复的条目。
虽然这不应该发生,但它曾经发生在我身上。
为了解决这个问题,我建议两个选项:
ADD UNIQUE INDEX
和/或PRIMARY KEY
。然后创建同样结构的表,添加缺失的索引,并INSERT IGNORE INTO new_tbl (SELECT * FROM tbl)
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:
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)
INSERT IGNORE
for the insert statement in the log要解决此问题,当您想要导出数据库时,可以尝试取消选中“格式特定选项:”下的“不要对零值使用 AUTO_INCRMENT”,请参见下图:
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 :