LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] MySQL and LOAD DATA

[ILUG] MySQL and LOAD DATA

Gavin McCullagh ilug_gmc at fiachra.ucd.ie
Thu Feb 28 16:13:34 GMT 2002




On Thu, 28 Feb 2002, Rory Winston wrote:

> Hi
> 
> 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!!

Two things.  

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.

Try this.

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
	[FIELDS
		[TERMINATED BY '\t']
		[[OPTIONALLY] ENCLOSED BY '']
		[ESCAPED BY '\\' ]
	]
	[LINES TERMINATED BY '\n']
	[IGNORE number LINES]
	[(col_name,...)]

I'm pretty sure this is right anyway,

Gavin






More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


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!
RSS Version
Powered by Dell