【问题标题】:MariaDB set timezone in configMariaDB 在配置中设置时区
【发布时间】:2014-12-08 14:12:29
【问题描述】:

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

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

default_time_zone,在原版 MySQL 上工作,无法被 MariaDB 识别。

【问题讨论】:

    标签: timezone mariadb


    【解决方案1】:

    default-time-zone- 而不是_):

    [server]
    default-time-zone=+00:00
    

    【讨论】:

    • 当我修改 /etc/my.cnf.d/server.conf 并运行 sudo systemctl start mariadb 我收到以下消息:Job for mariadb.service failed. See 'systemctl status mariadb.service' and 'journalctl -xn' for details.
    • 我没有 MariaDB 服务器来测试它,但测试套件使用这个设置:github.com/MariaDB/server/blob/10.1/mysql-test/suite/…
    • 使用“UTC”之类的名称假定您已运行 mysql_tzinfo_to_sql(有关详细信息,请参见手册页)。如果还没有,请尝试“default-time-zone=+00:00”。
    【解决方案2】:

    Pasi 的想法是正确的。 'UTC' 不起作用,但 '+00:00' 起作用。

    【讨论】:

      【解决方案3】:

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

      打开

      /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 // 这相当于 (america/edmonton)

      您需要确定您的时区,请查看此处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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-09
        • 1970-01-01
        • 1970-01-01
        • 2020-08-06
        • 1970-01-01
        • 1970-01-01
        • 2023-03-11
        • 1970-01-01
        相关资源
        最近更新 更多