我有一个mysql表,还有一个从mysql创建的csv文件。现在加载数据infile无法解析文件:
表格
CREATE TABLE `generic_alert_type` (
`generic_alert_type_id` int(11) NOT NULL AUTO_INCREMENT,
`generic_alert_type_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`keyword` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`pull_response_template` varchar(500) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Must contain placeholders like \\n#title#, #organization#, #location#, \\n#url#, #more#',
`menu_number` tinyint(4) NOT NULL,
`daily_mo_hits_column_name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The name of the column in daily_stats table, which will be incremented, when an mo is received for this generic alert type',
PRIMARY KEY (`generic_alert_type_id`),
UNIQUE KEY `menu_number_UNIQUE` (`menu_number`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
QUERY:
LOAD DATA LOCAL INFILE '/path/to/file.csv' INTO TABLE generic_alert_type FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES (generic_alert_type_id,generic_alert_type_name,keyword,pull_response_template,menu_number);
示例CSV:
generic_alert_type_id,generic_alert_type_name,keyword,pull_response_template,menu_number
"1","Internship Alerts","IA","Title: #title#. Organization: #organization#. Location: #location#. URL: #url# - Reply with #more# for More.","4"
"2","Training Alerts","TA","Title: #title#. Organization: #organization#. Location: #location#. URL: #url# - Reply with #more# for More.","5"
"3","Jobs Fact Book","FACT","#title# - Reply with #more# for more.","6"
警告:
+---------+------+---------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------------------------+
| Warning | 1265 | Data truncated for column 'menu_number' at row 1 |
| Warning | 1262 | Row 1 was truncated; it contained more data than there were input columns |
| Warning | 1366 | Incorrect integer value: '"6"
' for column 'menu_number' at row 2 |
+---------+------+---------------------------------------------------------------------------+