SpringBoot mysql出现The server time zone value '�й���ʱ��' is unrecogni
MySql :8.0.18
引入的mysql驱动:
SpringBoot整合Mybatis的框架,在访问Controller的时候 :
ava.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.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.18.jar:8.0.18]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.18.jar:8.0.18]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-java-8.0.18.jar:8.0.18]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-java-8.0.18.jar:8.0.18]
......
上网查找解决方案,发现是我的配置文件application.yml中数据库url地址的问题。
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/heima29
username: root
password: houchen
hikari:
maximum-pool-size: 20
minimum-idle: 10
mybatis:
type-aliases-package: cn.itcast.userservice.pojo
查询到的解决方案如下:(猜测估计是因为SpringBoot 2.1.x版本使用的的jdbc驱动是6.0版本以上吧)
原因是因为使用了Mysql Connector/J 6.x以上的版本,然后就报了时区的错误
遇到的问题: servertime=UTC导致时间差8个小时
MySQL jdbc 6.0 版本以上必须配置此参数
解决办法:
在配置url的时候不能简单写成 :jdbc:mysql://localhost:3306/mysql
而是要写成 :jdbc:mysql://localhost:3306/mysql?serverTimezone=UTC
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/heima29?serverTimezone=?serverTimezone=UTC
username: root
password: houchen
hikari:
maximum-pool-size: 20
minimum-idle: 10
mybatis:
type-aliases-package: cn.itcast.userservice.pojo
虽然上面加上时区程序不出错了,但是我们在用java代码插入到数据库时间的时候却出现了问题。
比如在java代码里面插入的时间为:2017-08-21 17:29:56
但是在数据库里面显示的时间却为:2017-08-21 09:29:56
因为时区设置的问题。
UTC代表的是全球标准时间 ,但是我们使用的时间是北京时区也就是东八区,领先UTC八个小时。
UTC + (+0800) = 本地(北京)时间
解决方案:
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/heima29?serverTimezone=Asia/Shanghai
username: root
password: houchen
hikari:
maximum-pool-size: 20
minimum-idle: 10
mybatis:
type-aliases-package: cn.itcast.userservice.pojo
SpringBoot mysql出现The server time zone value '�й���ʱ��' is unrecogni
SpringBoot mysql出现The server time zone value '�й���ʱ��' is unrecogni的更多相关文章
- spring boot 连接mysql 错误The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one
1.spring boot 整合mybatis 连接mysql时错误 The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or repr ...
- Mysql bug: The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone.
在 MySQL 中执行命令试下: set global time_zone='+8:00': 解释:在访问数据库时出现时区无法识别问题,在通过在数据库连接URL后,加上?serverTimezone= ...
- java连接mysql出现The server time zone value '�й���ʱ��' is unrecognized or represents more than...
在连接的配置文件中,指定数据库位置的末尾加上serverTimezone=UTC ```yml url: jdbc:mysql://localhost:3306/app?serverTimezone= ...
- [bug]mysql: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone
原因: 时区设置有误 解决: 在mysql中修改时区设置: 或 在JDBC代码中增加时区设置: Connection c = DriverManager.getConnection("jdb ...
- mysql的时区错误问题,The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one
在使用springboot整合ssm和druid的时候出现数据库一个问题 org.springframework.web.util.NestedServletException: Request pr ...
- com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'PDT' is.......
SpringBoot连接数据库的时候报错 java.sql.SQLException: The server time zone value 'PDT' is unrecognized or repr ...
- 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 tha ...
- Eclipse连接MySQL出现Server time zone is unrecognized错误
错误代码: The server time zone value '?й???????' is unrecognized or represents more than one time zone. ...
- MySQL连接数据库报时区错误:java.sql.SQLException: The server time zone value
连接MySQL数据库时报以下时区错误信息: java.sql.SQLException: The server time zone value '�й���ʱ��' is unrecognized ...
随机推荐
- osg osgViewer::View::setUpViewInWindow()
void ViewerBase::frame(double simulationTime) { if (_done) return; // OSG_NOTICE<<std::endl< ...
- ireport如何拼接sql?
ireport如何拼接sql ireport如何拼接sql? 解决方法: 1.ireport的sql select * from emp as e $P!{whereSQL}; 2.java代码 ...
- mysql 1577、1548错误 解决方案
mysql 1577.1548错误 解决方案 1.mysql版本: 5.5.12 2.问题原因: 使用Navicat导出数据库的提示 :1577 – Cannot proceed because sy ...
- iOS-UIView的layoutSubviews和drawRect方法何时调用(转)
转自:http://jianyu996.blog.163.com/blog/static/112114555201305113018814/ 首先两个方法都是异步执行.layoutSubviews方便 ...
- 基于MSP430F2618的程控电压源
基于MSP430F2618的程控电压源 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ 系列博客说明:此系列博客属于作者在大三大四阶段所储备的关于电子电路设计 ...
- java根据模板生成pdf
原文链接:https://www.cnblogs.com/wangpeng00700/p/8418594.html 在网上看了一些Java生成pdf文件的,写的有点乱,有的不支持写入中文字体,有的不支 ...
- EMR目录
EMR目录: E-MapReduce 是阿里云上的开源大数据平台,用户可以登录集群主节点查看相关安装路径. 登录后也可以使用 env |grep xxx 查看. 或者,在EMR Hadoop集群,切换 ...
- [转帖]一个关于国密SM4的故事
一个关于国密SM4的故事 https://www.cnblogs.com/ouyida3/p/10053862.html SM1 硬件SM2 非对称加密SM3 hash算法SM4 对称加密 一个关于国 ...
- 微软的一道网红Java面试题
题目: 给定一个int类型数组:int[] array = new int[]{12, 2, 3, 3, 34, 56, 77, 432}, 让该数组的每个位置上的值去除以首位置的元素,得到的结果,作 ...
- Spring Boot系列教程十三:Spring boot集成Sentinel Redis
前言 上一篇文章介绍了spring boot集成单点的redis,然而实际生产环境使用单点的redis风险很高,一旦宕机整个服务将无法使用,这篇文章介绍如何使用基于sentinel的redis高可用方 ...