MySQL weird issue while importing a large file: Du

2019-08-15 06:17发布

问题:

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