【问题标题】:Change MySQL Timezone Windows更改 MySQL 时区窗口
【发布时间】:2018-10-14 23:33:39
【问题描述】:

我尝试在 my.ini 中更改时区,但它不起作用。

使用不同的变体:

default-time-zone = "Europe/Moscow"
default_time_zone = "Europe/Moscow"
default-time-zone = "+03:00"
and so on

但是当我将其更改为 SET GLOBAL time_zone = '+3:00'; 时,一切正常。

我想更改时区,因为我的 REST API 不起作用并抛出异常:

com.mysql.cj.core.exceptions.InvalidConnectionAttributeException:服务器时区值“Russia TZ 2 Standard Time”无法识别或代表多个时区。

更新:

我发现我的安装有奇怪的行为:

当我通过 Workbench 更改 time_zone 时,它​​会在 ProgramData 中创建新文件夹。

现在它包含两个文件夹 MySQL Server 5.5MySQL Server 5.7。可能有问题。

【问题讨论】:

    标签: java mysql windows rest


    【解决方案1】:
    Login to your server via SSH as the root user.
    You can view MySQL's current time zone settings using the following command from the console:
    
    mysql -e "SELECT @@global.time_zone;"
    By default you should get back something similar to:
    
    +--------------------+
    | @@global.time_zone |
    +--------------------+
    | SYSTEM             |
    +--------------------+
    This is because by default your MySQL time zone will be set to the server's default SYSTEM time. If you're interested in changing the entire server's time zone this can be accomplished by setting the time zone in WHM.
    
    You can see the server's SYSTEM time stamp using the following command:
    
    date
    Which will give back:
    
    Mon Nov 26 12:50:07 EST 2012
    
    You can see the current time stamp reported by the MySQL server using the following command:
    
    mysql -e "SELECT NOW();"
    This should give back the current time stamp:
    
    +---------------------+
    | NOW()               |
    +---------------------+
    | 2012-11-26 12:50:15 |
    +---------------------+
    Now you can edit your MySQL configuration file with your favorite text editor:
    
    vi /etc/my.cnf
    Then add the following line to change from EST (GMT -5:00) to CST (GMT -6:00):
    
    default-time-zone = '-06:00'
    Now save the /etc/my.cnf file with your new default.
    
    To make the change active you'll want to restart the MySQL service with the following command:
    
    service mysql restart
    
    Now if you try to see the global time zone setting again with the command:
    
    mysql -e "SELECT @@global.time_zone;"
    You should now get back your new default:
    
    +--------------------+
    | @@global.time_zone |
    +--------------------+
    | -06:00             |
    +--------------------+
    You should also see now that the NOW() function has updated as well:
    
    mysql -e "SELECT NOW();"
    This should give back the current time stamp:
    
    +---------------------+
    | NOW()               |
    +---------------------+
    | 2012-11-26 11:50:15 |
    +---------------------+
    

    【讨论】:

    • 感谢您的回答,但它适用于 Linux 服务器。我使用的是 Windows 7。
    【解决方案2】:

    在 Windows 10 上,我发现我可以通过编辑“C:\ProgramData\MySQL\MySQL Server 8.0\Data\mysqld-auto.cnf”来做到这一点。

    "mysql_server" : { "time_zone" : { "Value" : "SYSTEM" ...
    

    编辑完这个文件后别忘了重启MYSQL80服务。

    【讨论】:

      【解决方案3】:

      Mysql提示:

      SELECT @@global.time_zone = "-4:00"

      之后:

      重启

      【讨论】:

      • 虽然此代码可以解决问题,including an explanation 说明如何以及为什么解决问题将真正有助于提高您的帖子质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人。请edit您的回答添加解释并说明适用的限制和假设。
      【解决方案4】:

      通过将 my.ini 文件添加到安装文件夹和 initialise 它解决了我的问题

      也可以这样做:

      SET GLOBAL time_zone = '+3:00';
      

      【讨论】:

        猜你喜欢
        • 2011-03-27
        • 2011-03-24
        • 2012-05-30
        • 2022-01-24
        • 2011-08-09
        • 2015-03-14
        • 1970-01-01
        • 1970-01-01
        • 2020-05-09
        相关资源
        最近更新 更多