I’m trying to import a csv (that is a data extract from a SQL Server db) into MySQL.
I’m using this command to load the file:
LOAD DATA INFILE '/Users/Tyler/Desktop/playersToTeams.txt' INTO TABLE players_to_teams FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
And I get this error:
Error Code: 1062. Duplicate entry '124547' for key 'PRIMARY'
When I run: grep 124547 playersToTeams.txt:
119683,True,True,124547,1493,2011-08-31 02:22:56.630000000,,,,,http://bucknellbison.cstv.com///sports/m-wrestl/mtt/stolfi_joe00.html,,,,,,
124547,True,True,129411,14726,2011-08-31 02:22:56.630000000,Free/Breast,,,,http://usctrojans.collegesports.com/sports/m-swim/mtt/walling_emmett00.html,,,,,,
I can see that the 4th column of the first entry has the same number as the first column (pk, id), but the 4th column doesn’t have any sort of index on it.
Here’s the create schema created by sql workbench:
CREATE TABLE `players_to_teams` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`IsActive` tinyint(1) DEFAULT NULL,
`IsVisible` tinyint(1) DEFAULT NULL,
`PlayerId` int(11) DEFAULT NULL,
`TeamId` int(11) DEFAULT NULL,
`CreationDate` datetime DEFAULT NULL,
`Position` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Number` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`Club` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`BT` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`BioLink` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`OtherBioLink` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`StartYear` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`EndYear` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`NeulionPlayerID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`SeasonYear` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`GamesPlayed` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=124549 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci$$
If I rerun the LOAD DATA command, without changing anything, I get a different error, this time the number is 2 more than the previous time (124549 vs. 124547). Running it again skips to 124552.
Any ideas what is causing this duplicate error?
Thanks
The file was ill-formatted. Props to @Vapire for thinking of that.