MySQL 时区

2021-11-20 00:00:00 timezone mysql

是否有详尽的 MySQL 时区列表?

Is there an exhaustive list of MySQL Time Zones?

似乎 MySQL 设置中 time_zone 的有效值取决于主机操作系统,但我无法找到可能值的列表.

It seems that the valid values for time_zone in MySQL settings are dependent on the host Operating System but I have been unable to find a list of possible values.

我需要时间显示卡尔加里当地时间.

I need the time to show Calgary local time.

推荐答案

来自 MySQL 5.7 文档(重点是我的):

From the MySQL 5.7 documentation (emphasis mine):

时区值可以以多种格式给出,没有一种是区分大小写:

timezone values can be given in several formats, none of which are case sensitive:

值 'SYSTEM' 表示时区应与系统时区.

The value 'SYSTEM' indicates that the time zone should be the same as the system time zone.

该值可以作为字符串给出,表示与 UTC 的偏移量,例如如+10:00"或-6:00".

The value can be given as a string indicating an offset from UTC, such as '+10:00' or '-6:00'.

该值可以作为命名时区给出,例如欧洲/赫尔辛基"、美国/东部"或MET".命名时区可以仅当mysql数据库中的时区信息表时使用已创建并填充.

The value can be given as a named time zone, such as 'Europe/Helsinki', 'US/Eastern', or 'MET'. Named time zones can be used only if the time zone information tables in the mysql database have been created and populated.

需要注意的是,MySQL timezone 变量在 MySQL 启动时的默认设置是 SYSTEM.SYSTEM 值是从操作系统设置中获取的(例如,从符号链接 /etc/localtime 引用的文件)

It should be noted that the MySQL timezone variable's default setting is SYSTEM at MySQL startup. The SYSTEM value is obtained from an operating system setting (e.g. from the file that is referenced by the symlink /etc/localtime)

MySQL 的默认 timezone 变量可以通过提供以下命令行选项在启动时初始化为不同的值:

MySQL's default timezone variable can be initialised to a different value at start-up by providing the following command line option:

--default-time-zone=timezone

或者,如果您在选项文件中提供值,则应使用以下语法来设置变量:

Alternatively, if you are supplying the value in an options file, you should use the following syntax to set the variable:

--default-time-zone='timezone'

如果您是 MySQL SUPER 用户,您可以在运行时使用以下语法从 MYSQL> 提示符设置 SYSTEM time_zone 变量:

If you are a MySQL SUPER user, you can set the SYSTEM time_zone variable at runtime from the MYSQL> prompt using the following syntax:

SET GLOBAL time_zone=timezone;

MySQL 还支持单独的 SESSION timezone 值,默认为 GLOBAL time_zone 环境变量值.要在 SESSION 期间更改会话 timezone 值,请使用以下语法:

MySQL also supports individual SESSION timezone values which defaults to the GLOBAL time_zone environment variable value. To change the session timezone value during a SESSION, use the following syntax:

SET time_zone=timezone;

为了查询现有的 MYSQL timezone 设置值,可以执行以下 SQL 来获取这些值:

In order to interrogate the existing MYSQL timezone setting values, you can execute the following SQL to obtain these values:

SELECT @@global.time_zone, @@session.time_zone;

对于它的价值,我只是在 google 上搜索了 mysql time_zone 配置有效值 并查看了第一个结果.

For what it's worth, I simply googled mysql time_zone configuration valid values and looked at the first result.

相关文章