1

I was trying to load a csv file into a table called Actors. What is the problem with this code?

LOAD DATA LOCAL INFILE 'actors.csv'
INTO TABLE Actors
FIELD TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"';
2
  • 1
    How about you tell us what the problem with the code is?
    – Steve
    Dec 28, 2014 at 19:07
  • I got an error called: ERROR 1064(42000) You have an error in your SQL syntax @ line 3. Dec 28, 2014 at 19:08

2 Answers 2

1

Your problem is with syntax.

Please refer to the MySQL Manual - 13.2.6 LOAD DATA INFILE Syntax. The correct syntax is FIELDS not FIELD.

Therefore it should be:

LOAD DATA LOCAL INFILE 'actors.csv'
INTO TABLE Actors
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"';
2
  • Thank you for your reply. I tried FIELDS, but still get the same error. Dec 28, 2014 at 19:14
  • 1
    There aren't any syntax issues in the code above so I find it hard to believe you're still getting a syntax error. Please visit the MySQL manual page I've linked to and read it - everything you need to know about LOAD DATA is contained within
    – Steve
    Dec 28, 2014 at 19:18
1

Try this code, ignore the last line if you don't have header(heading columns) at top of csv file

LOAD DATA LOCAL INFILE 'actors.csv' 
INTO TABLE Actors
FIELDS TERMINATED BY ',' 
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.