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 ‘?D1???×?ê±?‘ 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.28不会存在时区的问题,的确如此。

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

原文地址:https://www.cnblogs.com/godwithus/p/9788790.html

时间: 2024-08-24 17:05:04

MySql数据库时区异常,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.

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 v

nested exception is java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized异常

在连接数据库时出现以下异常 : nested exception is java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized 出现原因 : 数据库时区问题 解决办法 : 1. 在终端开启mysql, 输入以下命令 : show variables like '%time_zone%'; 2. 继续输入以下命令 : set global time_zone='+8:00'; nested e

连接mysql报错java.sql.SQLException: The server time zone value '?й???????' is unrecognized...解决方法

报错内容: 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

jeesite导入数据库错误:java.sql.SQLException: Incorrect string value: '\xE4\xB8\xAD\xE5\x9B\xBD' for column 'name' at row 1问题解决

如果使用mvn antrun:run -Pinit-db进行数据库导入导致出现如下错误: 解决方法: 这个是由于新建数据库没有选择默认字符集导致的,只要选择utf-8即可. jeesite导入数据库错误:java.sql.SQLException: Incorrect string value: '\xE4\xB8\xAD\xE5\x9B\xBD' for column 'name' at row 1问题解决

MySql中报错:java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\xBB' for column

问题描述: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\xBB' for column 'nickName' at row 1 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1094) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4226) at com.mysql.jdbc.M

Exception in thread “main” java.sql.SQLException: The server time zone value ‘?й???????’ is unrecognized or represents more than one time zone.

Exception in thread "main" 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) t

java.sql.SQLException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more

2018年08月15日 21:17:31 Going_cc 阅读数:34297 最近很多次遇到 The server time zone value '?D1ú±ê×?ê±??' is unrecognized or represents more than one time zone这个问题, 报错为: org.springframework.web.util.NestedServletException: Request processing failed; nested exception

java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized

Exception in thread "main" java.sql.SQLException: The server time zone value '?D1ú±ê×?ê±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property

Java spring boot 2.0连接mysql异常:The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone

解决办法:application.yml提示信息表明数据库驱动com.mysql.jdbc.Driver'已经被弃用了.应当使用新的驱动com.mysql.cj.jdbc.Driver' com.mysql.jdbc.Driver改成com.mysql.cj.jdbc.Driver 我接着运行项目有报错 解决办法: spring: datasource: url: jdbc:mysql://localhost:3306/boot?useUnicode=true&characterEncoding