MariaDB在config中设置时区

时间:2014-10-13 22:13:36

标签: timezone mariadb

如何在MariaDB配置中设置服务器时区?

我在文档中唯一能找到的就是使用命令行标志,我不想这样做。

default_time_zone,它适用于vanilla MySQL,不被MariaDB识别。

3 个答案:

答案 0 :(得分:6)

default-time-zone-代替_):

[server]
default-time-zone=UTC

答案 1 :(得分:3)

帕西有正确的想法。 'UTC'没有用,但'+00:00'没有用。

答案 2 :(得分:1)

以下是从上述问题和答案中收集的完整摘要:

打开

/etc/my.cnf.d/server.conf

更改为示例:

#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]
default-time-zone=-06:00

# this is only for the mysqld standalone daemon
[mysqld]

注意:用于字符串

default-time-zone = -06:00 // //相当于(美国/埃德蒙顿)

您需要找出自己的时区,以在此处https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

中查找

重新启动mysql服务器:

服务mariadb重新启动

测试:

[smith@home my.cnf.d]# mysql -u smith -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.2.31-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT now();
+---------------------+
| now()               |
+---------------------+
| 2020-04-22 11:19:38 |
+---------------------+
1 row in set (0.01 sec)