On Thu, 28 Feb 2002, Rory Winston wrote:
>> I am using MySQL 3.23.47 and am trying to load a .CSV file with employee
> details into it. The exact command I am using is:
>> LOAD DATA INFILE "foo.csv"
> INTO TABLE attendees (forename, surname, job_title, division)
> FIELDS TERMINATED BY ','
>> However, I get ERROR 1064: You have an error in your SQL syntax near 'FIELDS
> TERMINATED BY ','.
> If I leave out the FIELDS TERMINATED BY clause it will load the data, but
> since it doesnt recognize the comma delimiter, I get all the data in one
> column!! Arrgh!!
1. No semi-colon at end. This shouldn't cause a problem though
2. Syntax is wrong. FIELDS TERMINATED BY comes before the definition of fields you are
inserting into. This is probably the problem.
LOAD DATA INFILE "foo.csv"
INTO TABLE attendees
FIELDS TERMINATED BY ',' (forename, surname, job_title, division);
from the mysql manual
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt'
[REPLACE | IGNORE]
INTO TABLE tbl_name
[TERMINATED BY '\t']
[[OPTIONALLY] ENCLOSED BY '']
[ESCAPED BY '\\' ]
[LINES TERMINATED BY '\n']
[IGNORE number LINES]
I'm pretty sure this is right anyway,
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!