MySql LOAD DATA is ignoring my Primary Key id, and using autoincrement instead
I have a table that has a simple primary key, marked as auto_increment.
(Using MySQL 5.0.77) I do repeated LOAD DATA operations. I need to overwrite all of the data, with complete control over my primary key value.
LOAD DATA LOCAL INFILE "TopicInfile.dat" INTO TABLE Topic LINES TERMINATED BY "END-OF-THIS-RECORD";
The .dat file has the ID in it. It's not NULL. And yet, when I load this data, it behaves as if it was NULL, and assigns an autoincrement id, instead of using what I specified.
The only thing unusual about this .dat file is that it contains a lot of data. The .dat file has this structure:
1 2008-06-27 12:00:00 Type-Safe Enumerations Énumérations 5
...a lot of data here...
\N 2002-10-01 12:00:00 END-OF-THIS-RECORD
2 2008-06-27 12:00:00 Class for constants Classe pour constantes 1
...a lot of data here...
\N 2002-10-01 12:00:00 END-OF-THIS-RECORD
and so on
The table structure is :
CREATE TABLE `Topic` (
`Id` smallint(5) unsigned NOT NULL auto_increment,
`LastEdit` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`TitleEnglish` varchar(75) NOT NULL default '',
`TitleFrench` varchar(75) default NULL,
`ChapterId` smallint(6) NOT NULL default '0',
`BodyEnglish` text NOT NULL,
`BodyFrench` text,
`CreationDate` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`Id`)
) ENGINE=MyISAM AUTO_INCREMENT=251 DEFAULT CHARSET=utf8 |
I have other 开发者_Python百科tables for which the behavior is fine - the LOAD DATA operation always accepts my id value, except for the above Table.
Any help appreciated.
I don't know exactly why the items were treated as null.
I made some changes to the content of the input file (tab characters not quite right), and to the LOAD DATA command (EOL character not right), which is now behaving correctly:
See:
MySQL LOAD DATA with multiline data
精彩评论