MySQL CSV import: datetime value

后端 未结 4 1135
天命终不由人
天命终不由人 2020-12-17 03:28

I have been banging my head against a wall trying to import datetime values from a .csv file.

Here\'s the import statement.

LOAD DATA LOCAL INFILE \'m

4条回答
  •  猫巷女王i
    2020-12-17 04:06

    I was having the same trouble and here's what I discovered, I think it might help you

    The problem regards a GMT conflict: The database I was extracting the .csv file was on GMT 00:00, so there wasn't daylight saving time.

    My local server (which was the one I was trying to insert the .csv file) was running on my computer (system's) GMT, by default. In my case it was GMT -3, which is affected by daylight saving time.

    SQL has a special way to deal with daylight saving time, it ignores the exact date and time when the daylight saving time starts to happen. In my case, it was october 20 and all the records between 00 and 1 AM of that day simply weren't recognized by the server, even if the format was correct, because they simply 'didn't exist' (see more here). This was affecting all timestamp records, not only the specifics of daylight saving time.

    My solution was to set the local server to GMT +00, before creating the new table and import the .csv, using

    SET time_zone='+00:00';
    

    And then when I imported the .csv file all the records were read properly. I think if you set the time zone equal to the one that generated the .csv file should work!

提交回复
热议问题