配置 mySQL 以继承操作系统的时区

Configure mySQL to inherit the operating system's timezone

我们的本地时钟刚刚调快夏令时,和往常一样,我们的数据库服务器又关闭了一个小时。是否可以将 my.cnf 配置为简单地继承 Cent OS 的时区偏移量,或者我们注定要每六个月手动更改一次?

由于某些原因,我的回答被转换为评论,因为它很短。

您的数据库很可能设置为与服务器相同的时区。问题如下:

Neither the DATETIME nor the TIMESTAMP field types can accurately store data in a timezone that observes DST. If you store "2009-11-01 01:30:00" the fields have no way to distinguish which version of 1:30am you wanted -- the -04:00 or -05:00 version.

有关详细答案,请查看此处:

答案似乎是在/etc/my.cnf default-time-zone 之前添加一个散列来禁用它,然后重新启动MySQL。

As the manual describes, MySQL will default to system_time_zone 如果未明确设置默认值。

If this option is not given, the default time zone is the same as the system time zone (given by the value of the system_time_zone system variable.