Date value in mysql tables changes when exporting mysql db

I am exporting a mysql table to configure it in real time, but when exporting a DB I noticed that the value of the date column is changing. If it was " 2007-06-11 00:00:00 " earlier, after export, now it is changed to " 2007-06-10 18:30:00 ",

why is that so? Anyone have an idea about this?

+6
source share
2 answers

Error No. 13052 existed in versions of MySQL prior to 5.0.15, in which dump files expressed TIMESTAMP columns in the server time zone, but did not include the SET TIME_ZONE command to make sure that anyone (or any subsequent server) reading the dump file understood this is; without such a command, the receiving servers assume that any TIMESTAMP values ​​are in the default time zone.

Consequently, the transfer between servers in time zones offset by 6:30 p.m. (for example, from South Australia to California) will lead to the behavior that you observe.

Solutions to this problem in some vague order of preference include:

  • Upgrade the mysqldump version on the source server to version 5.0.15 or later (this will cause the dumpfile to express all TIMESTAMP values ​​in UTC with the appropriate SET TIME_ZONE statement at the beginning);

  • Before exporting (or importing), change the global variable time_zone on the source (or destination) server, so that it corresponds to the setting on another server during import (or export):

     SET GLOBAL time_zone = 'America/Los_Angeles'; -- ('Australia/Adelaide') 
  • UPDATE data after the fact using MySQL CONVERT_TZ() :

     UPDATE my_table SET my_column = CONVERT_TZ( my_column, 'America/Los_Angeles', 'Australia/Adelaide' ); 

If you are using solution 2 or solution 3, be careful to use the exact time zone of the corresponding time_zone server time_zone in such a way as to include any daylight saving time. Please note that, as described in MySQL Server Time Zone Support : "Named time zones can only be used if time zone information tables in the mysql database have been created and populated." The rest of the article explains how to create and populate timezone information tables.

+4
source

Before the export database, follow these steps:

export with custom option

uncheck the box below

 Dump TIMESTAMP columns in UTC (enables TIMESTAMP columns to be dumped and reloaded between servers in different time zones) 

shown below. enter image description here

+2
source

Source: https://habr.com/ru/post/945230/


All Articles