MySQL error loading data file

2019-09-17 10:42发布

问题:

i am trying to execute this query unfortunately i am getting an error ,can anyone tell why this error appear,where i went wrong

my query:

    LOAD DATA INFILE '/wamp/www/var/Book1.csv' INTO TABLE contact
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES
(
@dummy , @dummy , column1, @dummy , column3, column2, @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , column4, @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy
)  ;

Error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES' at line 4 

回答1:

You have to change the order of fields... and the column names:

LOAD DATA INFILE '/wamp/www/var/Book1.csv' INTO TABLE contact
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES
(
@dummy , @dummy , name, @dummy , nationality, mobile1, @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , twon, @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy , @dummy
)  ;


标签: mysql csv import