LOAD DATA LOCAL, How do I skip the first line?

SqlMysqlCsvImportLoad Data-Infile

Sql Problem Overview


I'm trying to Load a CSV file into my MySQL database, But I would like to skip the first line.

I fact It contains the name of my columns and no interesting data.

Here is the query I'm using:

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

Sql Solutions


Solution 1 - Sql

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

(reference)

Solution 2 - Sql

For those curious, IGNORE N LINES should be after the separator qualifiers:

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

Solution 3 - Sql

Try this:

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;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRochView Question on Stackoverflow
Solution 1 - SqlZedView Answer on Stackoverflow
Solution 2 - SqlChad GearyView Answer on Stackoverflow
Solution 3 - Sqlbharat bhagatView Answer on Stackoverflow