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

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

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

这是我正在使用的查询:

LOAD DATA LOCAL INFILE '/myfile.csv' 
INTO TABLE tableName
FIELDS TERMINATED BY ','
ENCLOSED BY '\"' 
LINES TERMINATED BY '\n' 
(column,column,column);
Roch asked 2019-11-08T10:47:24Z
2个解决方案
96 votes
LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test IGNORE 1 LINES;

(参考)

Zed answered 2019-11-08T10:47:39Z
29 votes

对于那些好奇的人,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);
Chad Geary answered 2019-11-08T10:48:04Z
translate from https://stackoverflow.com:/questions/1618355/load-data-local-how-do-i-skip-the-first-line