Peter Hwang
Peter Hwang

Reputation: 991

Loading a csv file

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 '"';

Upvotes: 1

Views: 84

Answers (2)

tzafar
tzafar

Reputation: 664

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

Upvotes: 1

Steve
Steve

Reputation: 3703

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 '"';

Upvotes: 1

Related Questions