LOAD简单的CSV文件MySQL

时间:2014-02-23 14:13:30

标签: mysql csv

尝试加载.csv这么简单:

"Id";"Values"
"1";"Value1"
"2";"Value2"
...
...
"n";"Valuen"

进入包含2个字段的表

id       int(11) primary
values   varchar(255)
像这样:

LOAD DATA LOCAL INFILE 'file_name.csv'
REPLACE
INTO TABLE tbl_name
FIELDS
    TERMINATED BY ';'
    ENCLOSED BY '"'

LINES TERMINATED BY '\n'
IGNORE 1 LINES

但是当我加载它时,我会得到像

这样的东西
+----+--------------+
| id | value        | 
+----+--------------+
|  1 | value1" "2   | 
|  2 | value3" "4   |
|  3 | value5" "6   |
|  4 | value7" "8   |
|  5 | value9" "10  | 
|  6 | value11" "12 | 
+----+--------------+

好像它不理解换行规则\ n

已经脱掉了我的头发。我做错了什么?

换句话说,加载此文件的正确查询是什么?

1 个答案:

答案 0 :(得分:1)

尝试下面的一个 -

LOAD DATA LOCAL INFILE 'file_name.csv' REPLACE INTO TABLE tbl_name FIELDS ESCAPED BY '\\' TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;