MySQL 服务器时区值“CEST”无法识别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49518683/
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
The server time zone value 'CEST' is unrecognized
提问by Filippodb
I am using hibernate (Hibernate Maven 5.2.15.Final, Mysql-connector Maven 8.0.9-rc) whith mysql 5.7 on lampp environment on linux so.
我在linux上的lampp环境中使用hibernate(Hibernate Maven 5.2.15.Final,Mysql-connector Maven 8.0.9-rc)和mysql 5.7。
I am in Italy (Central European Summer Time) and once March 25, occurs follow error on connection db:
我在意大利(中欧夏令时),一旦 3 月 25 日,连接数据库出现以下错误:
The server time zone value 'CEST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
服务器时区值“CEST”无法识别或代表多个时区。如果您想利用时区支持,您必须将服务器或 JDBC 驱动程序(通过 serverTimezone 配置属性)配置为使用更具体的时区值。
On mysql console, I ran:
在 mysql 控制台上,我跑了:
SHOW GLOBAL VARIABLES LIKE 'time_zone';
SET GLOBAL time_zone='Europe/Rome';
but that did not persist.
但这并没有持续下去。
Then I added to my.cnf
file (in /etc/mysql):
然后我添加到my.cnf
文件(在 /etc/mysql 中):
[mysqld]
default-time-zone = 'Europe/Rome'
and also:
并且:
default_time_zone = 'Europe/Rome'
but the db server did not start still...
但是数据库服务器还没有启动......
Why does the error occur? Could someone help me?
为什么会出现错误?有人可以帮助我吗?
Thank you!
谢谢!
回答by Claude Brisson
@aiman's answer is not correct since in your case the effective server timezone is notUTC.
@aiman 的答案不正确,因为在您的情况下,有效服务器时区不是UTC。
You'll find on the net some solutions including additional parameters on the jdbc connection string, but there are cases where you cannot change this string.
您会在网上找到一些解决方案,包括 jdbc 连接字符串上的附加参数,但有些情况下您无法更改此字符串。
Here's how I fixed it:
这是我修复它的方法:
First import the system timezones in mysql:
首先在mysql中导入系统时区:
$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
Then set your default mysql server timezone in the [mysqld]
section of /etc/mysql/my.cnf
(or of /etc/mysql/mysql.conf.d/mysqld.cnf
on recent Debian/Ubuntu distros) to your actual server timezone, for instance:
然后在(或最近的 Debian/Ubuntu 发行版)[mysqld]
部分中将您的默认 mysql 服务器时区设置为您的实际服务器时区,例如:/etc/mysql/my.cnf
/etc/mysql/mysql.conf.d/mysqld.cnf
default_time_zone = Europe/Paris
and don't forget to restart mysql
并且不要忘记重新启动mysql
$ sudo service mysql restart
(or the appropriate command depending on your distro).
(或适当的命令取决于您的发行版)。
回答by aiman
First see your mysql server timezone:mysql -e "SELECT @@global.time_zone;" -u <mysqluser> -p
.
Most probably it should be SYSTEM
.
Find your system timezone: date +”%Z
.
See if its CEST.
You need to change your system timezone:
首先查看您的 mysql 服务器时区:mysql -e "SELECT @@global.time_zone;" -u <mysqluser> -p
.
很可能应该是SYSTEM
。
找到您的系统时区:date +”%Z
.
看看它的 CEST。
您需要更改系统时区:
#cd /usr/share/zoneinfo
#ls -l
#rm /etc/localtime
#ln -s /usr/share/zoneinfo/UTC /etc/localtime
Then restart your mysql server: /etc/init.d/mysqld restart
.
然后重新启动MySQL服务器:/etc/init.d/mysqld restart
。
Enjoy
享受