更改 MySQL 中的连接时区
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5510052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing the connection timezone in MySQL
提问by Gowri
My server is running in MDT
我的服务器正在运行 MDT
So I used following one to convert EST
所以我用下面的一个来转换 EST
SET time_zone = '-5:00'
But, how can I switch it to EDT
because
但是,我怎么能切换到EDT
因为
While `EST` is only valid in winter, while in summer how to change it to `EDT`
I just try to used named time zone. But I am getting following error
我只是尝试使用命名时区。但我收到以下错误
#1298 - Unknown or incorrect time zone: 'America/Toronto'
I don't understand how to solve this problem
我不明白如何解决这个问题
How can i switch
我该如何切换
UTC -05 TO UTC-04
UTC -05 至 UTC-04
采纳答案by Alpha01
Since you're using Windows, your going to have to import the time zone description tables to your MySQL server.
由于您使用的是 Windows,因此您必须将时区描述表导入 MySQL 服务器。
回答by Steve Tauber
For Linux, BSD, and Mac OS X if you need to load the timezone table do this:
对于 Linux、BSD 和 Mac OS X,如果您需要加载时区表,请执行以下操作:
$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot mysql
回答by Andrew
For me on Windowsusing WampServer:
对于我在Windows 上使用WampServer:
- download the POSIX version from https://dev.mysql.com/downloads/timezones.html
- unzip it
- put all files in wamp mysql data: C:\wamp\bin\mysql\mysql5.7.11\data\mysql
- restart wamp
- 从https://dev.mysql.com/downloads/timezones.html下载 POSIX 版本
- 解压
- 将所有文件放在wamp mysql数据中:C:\wamp\bin\mysql\mysql5.7.11\data\mysql
- 重启wamp
More Info:
更多信息:
“To use a time zone package that contains .frm, .MYD, and .MYI files for the MyISAM time zone tables, download and unpack it. These table files are part of the mysql database, so you should place the files in the mysqlsubdirectory of your MySQL server's data directory. Stop the server before doing this and restart it afterward”
“要为 MyISAM 时区表使用包含 .frm、.MYD 和 .MYI 文件的时区包,请下载并解压缩它。这些表文件是 mysql 数据库的一部分,因此您应该将这些文件放在 MySQL 服务器数据目录的 mysqlsubdirectory 中。在执行此操作之前停止服务器,然后重新启动它”
http://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html#time-zone-installation
http://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html#time-zone-installation
回答by Jon Skeet
Have you tried using a zoneinfo name such as "America/New_York" instead of the abbreviation (which is only valid for half the time)?
您是否尝试过使用诸如“America/New_York”之类的 zoneinfo 名称而不是缩写(仅在一半时间内有效)?
Ideally, you shouldn't use the server time zone at all of course - store dates in UTC and then convert it to the appropriate time zone in the client code. (This does depend on what you're storing, mind you. Future date/time values specified by a user with a time zone should be stored that way, not converted to anyother time zone, in case the rules change between now and the future date/time. But for instants in time recorded by machines, e.g. for logging, transactions etc, I'd definitely store UTC. I would never suggest storing "just the local time and assume that the server and the client have the same rules".)
理想情况下,您当然不应该使用服务器时区 - 以 UTC 格式存储日期,然后在客户端代码中将其转换为适当的时区。(这确实取决于您要存储的内容,请注意。具有时区的用户指定的未来日期/时间值应以这种方式存储,而不是转换为任何其他时区,以防规则在现在和未来的日期/时间。但是对于机器记录的即时时间,例如日志记录、事务等,我肯定会存储 UTC。我永远不会建议存储“仅本地时间并假设服务器和客户端具有相同的规则”。)
回答by Nadeem Jamali
Just for the sake of completeness, Mac users can find mysql_tzinfo_to_sql
utility in /usr/local/mysql/bin
directory.
为了完整起见,Mac 用户可以mysql_tzinfo_to_sql
在/usr/local/mysql/bin
目录中找到实用程序。
Hence the complete command will be /usr/local/mysql/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysql
因此,完整的命令将是 /usr/local/mysql/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysql
I spent hours to find the utility, the above path may save yours!
我花了几个小时才找到该实用程序,上面的路径可能会保存您的路径!