LOAD DATA LOCAL,如何跳过第一行?

时间:2009-10-24 15:59:27

标签: sql mysql csv import load-data-infile

我正在尝试将CS​​V文件加载到我的MySQL数据库中, 但我想跳过第一行。

我确实它包含我的列的名称,没有有趣的数据。

以下是我正在使用的查询:

LOAD DATA LOCAL INFILE '/myfile.csv' 
INTO TABLE tableName
FIELDS TERMINATED BY ','
ENCLOSED BY '\"' 
LINES TERMINATED BY '\n' 
(column,column,column);

3 个答案:

答案 0 :(得分:95)

LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test IGNORE 1 LINES;

reference

答案 1 :(得分:25)

对于那些好奇的人,IGNORE N LINES应该在分隔符限定符之后:

LOAD DATA LOCAL INFILE '/myfile.csv' 
INTO TABLE tableName
FIELDS TERMINATED BY ','
ENCLOSED BY '\"' 
LINES TERMINATED BY '\n' 
IGNORE 1 LINES
(column,column,column);

答案 2 :(得分:0)

尝试一下:

IGNORE N LINES
LOAD DATA INFILE "/path/to/file.csv"
INTO TABLE MYTABLE 
COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;