This article is a mirror article of machine translation, please click here to jump to the original article.

View: 11497|Reply: 0

[Source] mysql #1062 –Duplicate entry '1' for key 'PRIMARY'

[Copy link]
Posted on 11/15/2017 1:22:06 PM | | |

Recently, I have been tossing VPS, and I just encountered the time when I imported the database in the process of moving wordpress. I met

#1062 – Duplicate entry '1′ for key ‘PRIMARY'

At that time, I was in a hurry, I had deleted all the original data, and I had no choice but to request the almighty Baidu. I searched for most of the day and finally found it for me. Excited, test it right away, O(∩_∩)O haha~ Success.

Now attached is a solution, just clear the original old data and import it.

I don't understand the principle, so stick it up and see for yourself. Anyway, it's OK to achieve the goal.

"Tip #1062 – Duplicate entry '1′ for key 'PRIMARY', I later found out that the last time the limit was exceeded has been imported partially, and the id is the main key, it cannot be the same, so it won't work, delete all the old data, and you can redirect."

I would also like to thank the blogger for publishing the solution. Otherwise, I'll be in trouble."

Original

The problem encountered today is very simple, but also very common, and I will record it here:
Import data from one machine to another, so there are too many records, I didn't pay attention at first, exceeded the limit of phpmyadmin, the prompt was wrong, I manually divided the file into some small files, but then it prompted #1062 - Duplicate entry '1' for key' PRIMARY', and later found out that the last time the limit was exceeded had been imported in part, and the id is the primary key, which cannot be the same, so it can't be done, delete all the old data, and you can re-direct.

All right. If you have the same problem as me, try it now. I don't know if I don't try


Mysql performs data backup, restores and replies, and the following error code appears:
Discuz! info: MySQL Query Error

User: webcull
Time: 2008-7-10 2:20pm
scrip{filter}t. /post.php

SQL: INSERT INTO [Table]posts (fid, tid, first, author, authorid, subject, dateline, message, useip, invisible, anonymous, usesig, htmlon, bbcodeoff, smileyoff, parseurloff, attachment)
VALUES ('45', '2727', '0', 'webcull', '6', '', '1216707030', 'ddd', '192.168.253.1', '0', '0', '0', '0', '-1', '-1', '', '0')
Error: Duplicate entry '2678' for key 1
Errno.: 1062


Reasons for online search analysis:
It may be that the field PID is the primary key and auto_increment attribute, and there can be no duplicate values.
And when I was backing up my data, there might be a data write that broke the data table.


Tried a few methods:
1. Some field attributes of the data table are missing ALTER TABLE 'cdb_posts' CHANGE 'pid' 'pid' INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT
2、repair table cdb_posts
All failed!


Final workaround:
Generally, it is caused by data table file corruption, which can be repaired by MySQL's repair tool myisamchk tool.
cmd
myisamchk cdb_posts.myi -r
Fix the datasheet and you're done!




Previous:July 2017 WIN7\XP· GHOST System Download Encyclopedia! Updates continue, exciting!
Next:Teach you how to use Myisamchk for crash recovery MySQL
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com