php phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3278470/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:12:47  来源:igfitidea点击:

phpmyadmin error "#1062 - Duplicate entry '1' for key 1"

phpmysqldatabasephpmyadminmysql-error-1062

提问by Jitendra Vyas

I dropped all tables from a database then restore(import) a backup. Afterwards I am getting error #1062 - Duplicate entry '1' for key 1.

我从数据库中删除了所有表,然后恢复(导入)了一个备份。之后我得到error #1062 - Duplicate entry '1' for key 1.

Should i repeat the process. Or something else? Why this error is coming?

我应该重复这个过程。或者是其他东西?为什么会出现这个错误?

回答by Gary Tsui

When you export your sql from php admin

当您从 php admin 导出 sql 时

enter image description here

在此处输入图片说明

Select "custom" as export method"

选择“自定义”作为导出方式”

enter image description here

在此处输入图片说明

then, instead of 'insert', choose "update"

然后,而不是“插入”,选择“更新”

This will perform update-statements and prevent duplicated inserts.

这将执行更新语句并防止重复插入。

回答by thomasrutter

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.

这表明您在表上有一个 UNIQUE 或 PRIMARY 索引,并且在将插入这些索引之一的值之一上存在重复值。

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 shouldtell you which row of data caused the problem, shouldn't it?

您需要查看导致此错误的特定操作,以找出它尝试写入的表和行。希望 phpMyAdmin应该告诉您是哪一行数据导致了问题,不是吗?

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.

一种猜测是您导入的数据与表中已有的数据重复,即您可能没有像您想象的那样删除现有数据。但它可以是任意数量的东西。

回答by Noam

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:

虽然这不应该发生,但它发生在我过去。为了解决这个问题,我建议两种选择:

  1. Manually remove the ADD UNIQUE INDEXand/or PRIMARY KEYat the start of each table dump. Then create a same structure table, add the missing index, and INSERT IGNORE INTO new_tbl (SELECT * FROM tbl)
  2. Adding INSERT IGNOREfor the insert statement in the log
  1. 在每个表转储开始时手动删除ADD UNIQUE INDEX和/或PRIMARY KEY。然后创建一个相同的结构表,添加缺失的索引,并INSERT IGNORE INTO new_tbl (SELECT * FROM tbl)
  2. INSERT IGNORE为日志中的插入语句添加

回答by rusly

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 :

要解决此问题,当您想导出数据库时,您可以尝试取消勾选“格式特定选项:”下的“不要将 AUTO_INCREMENT 用于零值”,请参见下图:

enter image description here

在此处输入图片说明