MySQL #1062 –duplicate entry ' 1 ' for key ' PRIMARY ' _mysql

Source: Internet
Author: User
Tags mysql query import database
Recently has been tossing VPS, just encountered in the process of moving WordPress Import database. Ran into

#1062 –duplicate entry ' 1′for key ' PRIMARY '

At that time the urgent ah, the original data I have all deleted, there is no way only to request the almighty Baidu. I looked for more than half a day to finally find me. Excited ing, immediately tested, O (∩_∩) o haha ~ succeeded.

Now attached to the solution as long as the original old data empty import on it.

Principle I do not understand, put it up and see for yourselves. Anyway, it's OK to achieve the goal.

"Tip #1062–duplicate entry ' 1′for key ' PRIMARY ', later know, the original last exceeded the limit has been a part of the guide, and ID is the primary key, can not be the same, so it is not, the old data are deleted, you can again guide. ”

Thanks also to the blogger for publishing the solution. Or else I'll be in trouble.

Original

The problems encountered today are very simple, but also very common, make a note here:
The data from a machine to another machine, so there are too many records, just at the beginning did not notice, more than the phpmyadmin limit, prompted a mistake, I put the file manually into small files, but then prompted #1062-duplicate entry ' 1 ' for key ' PRIMARY ', later know, the original last exceeded the limit has been a part of the guide, and ID is the primary key, can not be the same, so it is not, the old data are deleted, you can again guide.

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


MySQL data backup, restore after the reply, the following error code appears:
discuz! Info:mysql Query Error

User:webcull
Time:2008-7-10 2:20pm
Script./post.php

Sql:insert into [Table]posts (FID, Tid, A, author, Authorid, subject, Dateline, message, USEIP, invisible, anonymous, Usesig, Htmlon, Bbcodeoff, Smileyoff, Parseurloff, Attachment)
VALUES (' ', ' 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


Online Search Analysis reasons:
It is possible that the field PID is primary key and the Auto_increment property cannot have duplicate values.
While I was backing up the data, there might be data writes that corrupted the datasheet.


Some methods were tried:
1. data table partial field property loss ALTER table ' cdb_posts ' change ' pid ' pid ' INT (a) UNSIGNED not NULL auto_increment
2, Repair table cdb_posts
All failed!


The Final Solution:
Usually because of the data table file damage caused by the use of the MySQL Repair tool myisamchk tool repair.
Cmd
Myisamchk Cdb_posts.myi-r
Fixing the datasheet is OK!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.