MySql数据库时区异常,java.sql.SQLException: The server time zone value '?й???׼ʱ?' is unrecognized or represents more than one time zone.


JDBC访问MySql异常

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.sql.SQLException: 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 property) to use a more specifc time zone value if you want to utilize time zone support.

原因分析

数据库安装时默认为英语,0:00时区

Windows系统中,XP的时区是GMT,而Win7的时区是UTC。

mysql返回的时间会比实际时间要早8小时。

解决方案,以下任选一种即可解决问题:

1、配置JDBC连接参数

在url连接字符串后面加上?serverTimezone=UTC

例如:
jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&serverTimezone=UTC

jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF8&serverTimezone=UTC

学点新知识:

UTC,世界均衡时间

GMT,格林尼治时间

北京时间(东八区),GMT+8,url中表示为:&serverTimezone=GMT%2B8

jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&serverTimezone=GMT%2B8

我们一般认为GMT和UTC是一样的,都与英国伦敦的本地时相同。

2、修改MySQL数据库配置,需要DBA的root权限

使用root用户登录mysql

--查看时区值
show variables like '%time_zone%';

--设置为东八区(北京时间)
set global time_zone='+8:00';

 

3、有人说,使用低版本的MySQL jdbc驱动,5.1.47不会存在时区的问题,的确如此。


免责声明!

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



猜您在找 java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone 解决java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone SpingBoot 错误 java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone... eclipse连接mysql数据库提示The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.解决方法 java.sql.SQLException: The server time zone value '脰脨鹿煤卤锚脳录脢卤录盲' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver 解决使用DBeaver连接MySQL时报错-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 mysql连接异常:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zo错误 报错: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 springboot报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM