问题描述
我在 Linux 上的 Lampp 环境中使用休眠(Hibernate Maven 5.2.15.Final,Mysql-connector Maven 8.0.9-rc)和 mysql 5.7.
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.
我在意大利(中欧夏令时),一次 3 月 25 日,连接数据库出现以下错误:
I am in Italy (Central European Summer Time) and once March 25, occurs follow error on connection db:
服务器时区值CEST"无法识别或代表更多超过一个时区.您必须配置服务器或 JDBC驱动程序(通过 serverTimezone 配置属性)使用更多如果您想利用时区支持,请指定特定时区值.
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.
在 mysql 控制台上,我运行:
On mysql console, I ran:
SHOW GLOBAL VARIABLES LIKE 'time_zone';
SET GLOBAL time_zone='Europe/Rome';
但这并没有持续下去.
然后我添加到 my.cnf
文件(在/etc/mysql 中):
Then I added to my.cnf
file (in /etc/mysql):
[mysqld]
default-time-zone = 'Europe/Rome'
还有:
default_time_zone = 'Europe/Rome'
但是 db server 仍然没有启动...
but the db server did not start still...
为什么会出现错误?有人可以帮助我吗?
Why does the error occur? Could someone help me?
谢谢!
推荐答案
@aiman 的答案不正确,因为在您的情况下,有效的服务器时区是 not UTC.
@aiman's answer is not correct since in your case the effective server timezone is not UTC.
您会在网上找到一些解决方案,包括 jdbc 连接字符串上的附加参数,但在某些情况下您无法更改此字符串.
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.
这是我修复它的方法:
首先在mysql中导入系统时区:
First import the system timezones in mysql:
$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
然后在 /etc/mysql/my.cnf
的 [mysqld]
部分(或 /etc/mysql/mysql.conf.d/mysqld.cnf
在最近的 Debian/Ubuntu 发行版上)到您的实际服务器时区,例如:
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:
default_time_zone = Europe/Paris
别忘了重启mysql
$ sudo service mysql restart
(或适当的命令,具体取决于您的发行版).
(or the appropriate command depending on your distro).
这篇关于服务器时区值“CEST"无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!