MySQL weird issue while importing a large file: Duplicate entry for key 'PRIMARY'

情到浓时终转凉″ 提交于 2020-01-24 23:39:08

问题


My hosting company wants me to move from a MySQL 4 server to a MySQL 5.5 one. My database is relatively big as my website hosts the data of nearly 200,000+ registered users.

I made an export of all my tables using PHPMyAdmin and I am now trying to import them into the new server. Everything went fine until I tried to import the 'user' table. For information, here is its structure:

CREATE TABLE IF NOT EXISTS `user` (
`login` varchar(32) NOT NULL DEFAULT '',
`firstname` varchar(255) NOT NULL DEFAULT '',
`lastname` varchar(255) NOT NULL DEFAULT '',
`email` varchar(255) NOT NULL DEFAULT '',
...
PRIMARY KEY (`login`),
KEY `country_code` (`country_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Nothing spectacular, right? Using the PHPMyAdmin import tab, I uploaded the SQL file. Suddenly, I got the following error:

#1062 - Duplicate entry 'Jobi' for key 'PRIMARY' 

I immediately queried the database and search for a username whom login was 'Jobi'. No match!

I had a look at the query which generated the error and tried to do it manually...

INSERT INTO `ft_user`
  (`login`, `firstname`, `lastname`, `email`, ...)
VALUES
  ('Jobi', 'Lorem-First', 'Ipsum-Last', 'xxxxx@yyyy.com', ...);

and it worked just fine!

I made the test on my development machine and got the same error. Could someone explain me what I am doing wrong here?

Thank you in advance. Any help is really appreciated.

Hervé.


回答1:


If the input file contains two copies of a record with the same primary key value you could get this error, but then when the transaction gets rolled back that key would no longer exist. Check your input file for duplicates.




回答2:


In phpMyAdmin , in Settings tab, you can try checking the following values:

Settings -> SQL Queries -> Ignore multiple statement errors If you are using CSV format:

Settings -> Import -> CSV -> Do not abort on INSERT error If you are using SQL format:

Settings -> Export -> SQL -> Use ignore inserts



来源:https://stackoverflow.com/questions/10990908/mysql-weird-issue-while-importing-a-large-file-duplicate-entry-for-key-primary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!