Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql Load data infile ignore 1 lines not working

Tags:

mysql

I want to import a CSV file to my Mysql table using Load data infile: here's my current code :

    LOAD DATA INFILE '../myfile.csv'
          INTO TABLE data 
        FIELDS
            TERMINATED BY ','
            ENCLOSED BY '"'
            ESCAPED BY '"' 
LINES TERMINATED BY '\n' IGNORE 1 LINES (@f1,@f2...) set `f1`=@f1,...,fk=13 ;

This is the first part of the csv file :

Timestamp,FromName,FromID,FromA,FromAID,FromURL,ToCName,ToCID,ToCTarget,ToAName,ToAID,ToAURL,UUID,Model,OS,Country,Type,Value
"2012-10-29 07:02:20","NH","4f7898654fgh02","Halloween Game","589754hj67d00021","78643609","","","","Game 1™","4f754hj67d00014","58975449","988675ffgh555f3284530","iPhone","5.1.1","GB","cpi","0.5" 

this gives me a 0 rows inserted, but if i replace IGNORE 1 LINES with IGNORE 0 LINES the file is imported successfully (of course without ignoring the first line).

Any help is appreciated.

like image 254
joprog Avatar asked Oct 06 '22 02:10

joprog


1 Answers

Removing this line solved the problem :

ESCAPED BY '"'

working code :

LOAD DATA INFILE '../myfile.csv'
          INTO TABLE data 
        FIELDS
            TERMINATED BY ','
            ENCLOSED BY '\"'
LINES TERMINATED BY '\n' IGNORE 1 LINES (@f1,@f2...) set `f1`=@f1,...,fk=13 ;
like image 165
joprog Avatar answered Oct 10 '22 03:10

joprog