I’m trying to import a CSV into mysql, and my DateTime column doesn’t import successfully. I found some other posts on this, but others posts either:
- Require a separate script to do the import
- Or deal with the problem of milliseconds being truncated (while my problem is the entire DateTime field gets imported as 00
This is what I’m doing:
Cmd.exe: echo "1","2011-11-08 17:33:33" > foo.csv
Mysql:
CREATE TABLE `foo` (SomeId INT, SomeDateTime DATETIME);
LOAD DATA LOCAL INFILE "c:\\tmp\\foo.csv"
INTO TABLE `foo`
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
The row gets imported, but with 0000-00-00 00:00:00 instead of the date I entered. Is there a way to resolve this using the builtin LOAD DATA command – without creating a script to insert the data?
I had several problems in the import that were caused by extra whitespace.
My file was actually delimited by “, ” (comma + space) – not by “,” – and lines were terminated by
\r\ninstead of\n.