MySQL #1062-duplicate entry "1" for key "primary"

Source: Internet
Author: User
Tags wordpress migration

VPs has been around for a long time. I just encountered importing a database during the WordPress migration process. Met

#1062-duplicate entry '1' for key 'primary'

At that time, I was so anxious that I had deleted all the original data and could not only request the omnipotent Baidu. I finally found it for me for a long time. Excited ing, test now, O (lead _ Wait) O Haha ~ Succeeded.

Now we have attached a solution to clear the old data and import it.

I don't understand how it works. paste it here for yourself. It's okay to achieve the goal anyway,

"Prompt #1062-duplicate entry '1' for key 'primary'. Later, I realized that the previous time that exceeds the limit, I imported a part, and ID is the primary key, it cannot be the same, so it won't work. If you delete all the old data, you can re-import it."

I would like to thank the blogger for providing the solution. Otherwise, I will be in trouble.

Original

The problem we encountered today is very simple, but it is also very common. Make a record here:
The data is exported from one machine to another, so there are too many records. I didn't pay attention to it at the beginning. The phpMyAdmin limit is exceeded and an error is prompted, I manually divided the file into some small files, but the prompt #1062-duplicate entry '1' for key 'Primary 'is displayed after being imported, it turns out that some of the previously exceeded restrictions have been imported, and the ID is the primary key, which cannot be the same, so it will not work. If you delete all the old data, you can re-import it.

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

MySQL backs up data and replies after restoration. The following error occurs:Code:
Discuz! Info: MySQL query Error

User: webcull
Time:
Script./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', '20170', '0', 'webrule', '6', '', '123', 'ddd ', '123. 168.253.1 ', '0', '0', '0', '0','-1', '-1', '', '0 ')
Error: duplicate entry '000000' for key 1
Errno.: 1062

Reasons for online search analysis:
It may be because the PID of the field is the primary key and the auto_increment attribute cannot contain duplicate values.
When I back up data, some data may be written to the damaged data table.

Tried Some methods:
1. Lost alter table 'cdb _ posts' change 'pid ''pid 'int (10) unsigned not null auto_increment
2. Repair table cdb_posts
All failed!

Final Solution:
it is generally caused by damage to data table files. You can use the MySQL Repair Tool myisamchk to fix the problem.
CMD
myisamchk cdb_posts.myi-r
fix the data table!

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.