The default date format of a date column is YYYY-MM-DD HH:MM:SS
in MySQL.
The data file that I am trying load from has a date field that has the date in
Your format string for STR_TO_DATE()
is invalid. Hours in your sample data have 24-hour format (%H
or %k
) instead of 12-hour (%h
). You can see all possible date format specifiers here.
Change
%d-%b-%y %h:%i:%s
to
%d-%b-%y %H:%i:%s
^^
Your statement might look like this
LOAD DATA INFILE '/path/to/temp_test.csv'
IGNORE INTO TABLE temp_test
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n' -- or '\n'
IGNORE 1 LINES
(@c1, c2)
SET c1 = STR_TO_DATE(@c1,'%d-%b-%y %H:%i:%s');
After loading with your sample data
mysql> select * from temp_test; +---------------------+------+ | c1 | c2 | +---------------------+------+ | 2012-06-07 22:50:19 | abc | | 2013-06-07 22:50:19 | bcd | +---------------------+------+ 2 rows in set (0.00 sec)