我正在尝试使用以下命令将从SQL Server导出的数据加载到MySQL中:
mysql databasename -e"LOAD DATA INFILE '/home/calendar.txt' INTO TABLE events FIELDS TERMINATED BY '\\t' OPTIONALLY ENCLOSED BY '\'' LINES TERMINATED BY '\\n' (id,catid,title,state,created,publish_up,publish_down,event_status,alldayevent,approved,UnSpecifiedEndTime);"
文件calendar.txt具有以下格式:
7300 1143 'item 1' 1 2012-01-03 15:30:14 2012-1-8 17:30:00 2012-1-8 00:00:00 Pending 0 1 '1'
7301 1143 'item 2' 1 2012-01-03 15:30:14 2012-1-8 17:30:00 2012-1-8 00:00:00 Pending 0 1 '1'
7302 1143 'item 3' 1 2012-01-03 15:30:14 2012-1-8 17:55:00 2012-1-8 00:00:00 Pending 0 1 '1'
7303 1143 'item 4' 1 2012-01-03 15:30:14 2012-1-8 19:15:00 2012-1-8 00:00:00 Pending 0 1 1
7304 61 'item 5' 1 2012-01-03 15:30:14 2012-1-8 19:30:00 2012-1-8 00:00:00 Pending 0 1 1
7644 1053 'item 6' 1 2012-01-03 15:30:14 2012-1-8 00:00:00 2012-1-8 00:00:00 Pending 1 1 1
7305 1143 'item 7' 1 2012-01-03 15:30:14 2012-1-9 00:00:00 2012-1-9 00:00:00 Pending 1 1 1
7306 1056 'item 8' 1 2012-01-03 15:30:14 2012-1-9 8:10:00 2012-1-9 00:00:00 Pending 0 1 1
UnSpecifiedEndTime列未正确填充,如果您在导入后在phpmyadmin中查看它看起来为空白,为了使其填充您必须添加其他选项卡和字段,这似乎是字段计数问题但是我找不到任何东西,所有其他字段似乎都以正确的顺序填充。
用引号括起来的结束字段没有任何区别,我试图插入的字段类型定义为:
enum('0', '1')
任何帮助非常感谢
用于创建有问题的表的SQL是:
CREATE TABLE IF NOT EXISTS `events` (
`id` int(12) NOT NULL auto_increment,
`sid` int(11) NOT NULL default '0',
`catid` int(11) NOT NULL default '1',
`title` varchar(200) NOT NULL,
`content` longtext NOT NULL,
`adresse_info` varchar(120) NOT NULL default '',
`contact_info` varchar(120) NOT NULL default '',
`extra_info` varchar(240) NOT NULL default '',
`color_bar` varchar(8) NOT NULL default '',
`useCatColor` tinyint(1) NOT NULL default '0',
`state` tinyint(3) NOT NULL default '0',
`mask` int(11) unsigned NOT NULL default '0',
`created` datetime NOT NULL default '0000-00-00 00:00:00',
`created_by` int(11) unsigned NOT NULL default '0',
`created_by_alias` varchar(100) NOT NULL default '',
`modified` datetime NOT NULL default '0000-00-00 00:00:00',
`modified_by` int(11) unsigned NOT NULL default '0',
`checked_out` int(11) unsigned NOT NULL default '0',
`checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00',
`publish_up` datetime NOT NULL default '0000-00-00 00:00:00',
`publish_down` datetime NOT NULL default '0000-00-00 00:00:00',
`images` text NOT NULL,
`reccurtype` tinyint(1) NOT NULL default '0',
`reccurday` varchar(4) NOT NULL default '',
`reccurweekdays` varchar(20) NOT NULL default '',
`reccurweeks` varchar(10) NOT NULL default '',
`approved` tinyint(1) NOT NULL default '1',
`ordering` int(11) NOT NULL default '0',
`archived` tinyint(1) NOT NULL default '0',
`access` int(11) unsigned NOT NULL default '0',
`hits` int(11) NOT NULL default '0',
`event_status` enum('Pending','Complete','Postponed','Cancelled') NOT NULL,
`postponed_child_eventid` int(11) NOT NULL,
`Editor` int(11) NOT NULL,
`reason_to_change` text NOT NULL,
`alldayevent` tinyint(1) NOT NULL default '0',
`UnSpecifiedEndTime` enum('0','1') NOT NULL default '0',
`notice_is_holiday` tinyint(1) NOT NULL,
`notice_spdesk_ticker` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `catid` (`catid`),
KEY `publish_down` (`publish_down`),
KEY `publish_up` (`publish_up`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7645 ;
答案 0 :(得分:0)
检查文件中的字段分隔符,在LOAD DATA INFILE语句中它是一个TAB符号,但在您的示例(文件calendar.txt)中,它们是空格。
另外,更改
FIELDS TERMINATED BY '\\t' to FIELDS TERMINATED BY '\t'
和
LINES TERMINATED BY '\\n' to LINES TERMINATED BY '\n'