Page 1 of 1

Loading data with INFILE

PostPosted: 18. February 2009 04:30
by georgec
I would like to import data from a csv and at the same time alter a date field from YYYY-MM-DD to MM-DD-YYYY. If I use the following command, where do I place my source .csv file?

LOAD DATA [LOCAL] INFILE 'file_name'
INTO TABLE tbl_name
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1,field2,field3,varcharDate,...)
SET `date` = STR_TO_DATE( varcharDate, '%m-%d-%Y' ) ;

Re: Loading data with INFILE

PostPosted: 18. February 2009 08:23
by Wiedmann
If I use the following command

You get an error message... (brackets "[" / "]" surrounds an optional part, which must be used without the brackets).

where do I place my source .csv file?

This depends on, if you use "local" or not:
http://dev.mysql.com/doc/refman/5.1/en/load-data.html