MySql LOAD DATA 忽略我的主键 id,并使用自动增量代替
我有一个表,它有一个简单的主键,标记为 auto_increment。
(使用 MySQL 5.0.77)我重复执行 LOAD DATA 操作。我需要覆盖所有数据,并完全控制我的主键值。
将数据本地内文件“TopicInfile.dat”加载到以“END-OF-THIS-RECORD”结尾的表主题行中;
.dat 文件中包含 ID。它不是 NULL。然而,当我加载此数据时,它的行为就像 NULL 一样,并分配一个自动增量 id,而不是使用我指定的内容。
该 .dat 文件唯一不寻常的地方是它包含大量数据。 .dat 文件具有以下结构:
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
等等
表结构是:
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 |
我还有其他表,其行为良好 - LOAD DATA 操作始终接受我的 id 值,除了上面的表。
任何帮助表示赞赏。
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 tables for which the behavior is fine - the LOAD DATA operation always accepts my id value, except for the above Table.
Any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道为什么这些项目被视为空。
我对输入文件的内容(制表符不太正确)和 LOAD DATA 命令(EOL 字符不正确)进行了一些更改,现在它的行为正确:
请参阅:
MySQL 使用多行数据加载数据
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