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! |