I am loading data from text file to mysql table using following query:
LOAD DATA INFILE "myFile.csv"
INTO TABLE some_table
COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n' (admin,consumer);
But when my file contains some error lines it is not able skip that line and the whole process stops at that place. I mean if my file format like :
----------
sankr : kumar
----------
ramesh:rao
----------
new users add here
----------
sri : vennla
----------
anu : bhavya
----------
I have to load by skipping the line "new users add here". How can do this?
解决方案
The keyword you're looking for is IGNORE.
As in:
LOAD DATA INFILE "myFile.csv" IGNORE
INTO TABLE some_table
COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n' (admin,consumer);