JDBC driver连接MySQL运行报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than


出错原因:

因为安装mysql的时候时区设置的不正确。 mysql默认的是美国的时区,而我们中国大陆要比他们迟8小时,采用GMT+8:00格式。

也就是说是数据库和系统时区差异所造成的。

 

验证:运行cmd登录mysql,控制台输入:

 

show variables like '%time_zone%';

如果显示SYSTEM则是时区有问题,有两个解决方法:

 

 

解决方法一:

在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,如果需要使用gmt+8时区,需要写成GMT%2B8。

1.1

按照网上的教程,我第一次是在数据库后面加上(没有引号):"?serverTimezone=GMT+8"

报错:java.sql.SQLException: No timezone mapping entry for 'GMT 8' ; 

 

1.2

后来又查到,需要将+改成%2B,"?serverTimezone=GMT%2B8"就可以了:

 1.3 

 有大神提到:如果把数据库时区改了,那么插入数据库的时间都会自动减8小时。(暂时还没有用到)

解决方案:比如是SpringBoot2.0,在jdbc配置上加了一个&serverTimezone=UTC就行了。

 

解决方法二:

修改MySQL的配置文件,MySQL配置文件是my.ini文件在你的安装目录下去找,我的是C:\web\mysql-8.0.13\my.ini

用记事本打开,在[mysqld]节点后面加上这句话:

default-time-zone='+08:00'

再次运行:

show variables like '%time_zone%';

 

显示+8:00就成功了:

 此时不用在写?serverTimezone=GMT%2B8都可以运行成功。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 DBEAVER连接MySQL运行报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than 使用JDBC连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration 关于MySql升级JDBC架包导致时区问题报错(The server time zone value '?й???????' is unrecognized or represents more than one time zone) 解决使用DBeaver连接MySQL时报错-The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. 报错:Cannot create PoolableConnectionFactory (The server time zone value 'CST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverT mysql连接异常:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zo错误 JDBC连接数据库报错:java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. ...... 解决JDBC连接MySQL 8时得异常:java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. mysql运行报The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone的解决方法 springboot报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone
 
粤ICP备18138465号  © 2018-2026 CODEPRJ.COM