我正在尝试将CSV文件加载到我的MySQL数据库中, 但我想跳过第一行。
我确实它包含我的列的名称,没有有趣的数据。
以下是我正在使用的查询:
LOAD DATA LOCAL INFILE '/myfile.csv'
INTO TABLE tableName
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
(column,column,column);
答案 0 :(得分:95)
LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test IGNORE 1 LINES;
答案 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;