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 ...
随机推荐
- 阶段5 3.微服务项目【学成在线】_day16 Spring Security Oauth2_18-认证接口开发-接口开发-service
定义AuthController 实现刚才写的api接口 controller定义热requestMapping 是 / 就可以了. 因为我们的登陆跟路径就是/auth. 这样到login就是 /au ...
- 阶段5 3.微服务项目【学成在线】_day16 Spring Security Oauth2_08-SpringSecurityOauth2研究-解决swagger-ui无法访问
3.3.4.4 解决swagger-ui无法访问 当课程管理加了授权之后再访问swagger-ui则报错: 这里默认配置的了所有的请求都必须认证 把图片认证的路径加进去的话 那么访问课程图片的列表 就 ...
- iOS 判断scrollView是否滑动到底部
判断scrollView有没有滚动到视图的底部,用来判断下拉刷新的时间.等 - (void)scrollViewDidScroll:(UIScrollView *)scrollView1 { CG ...
- mybatis/tk mybatis下实体字段是关键字/保留字,执行报错
实体如下: import com.fasterxml.jackson.annotation.JsonFormat; import com.xxx.web.bean.PagesStatic; impor ...
- pip3快速下载paddle
安装百度的paddle paddle时很慢,后来采用国内的源,速度嗖嗖滴 pip3 install -U paddlepaddle -i https://pypi.douban.com/simple/ ...
- Golang 异常/日志处理
1.xerrors 异常 xerrors 包是一个非常棒的设计,不同于往常语言如java/php,因为go的errors只是一个string类型的映射,所以内存占用空间很少.这在golang的核心库和 ...
- 【数据库开发】在Windows上和Linux上配置MySQL的过程
[数据库开发]在Windows上和Linux上配置MySQL的过程 标签(空格分隔): [编程开发] 首先是在Windows上尝试用QT进行MySQL数据库开发,结果总出现driver不能load的错 ...
- 最新 草花互动java校招面经(含整理过的面试题大全)
从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.草花互动等10家互联网公司的校招Offer,因为某些自身原因最终选择了草花互动.6.7月主要是做系统复习.项目复盘.Leet ...
- Codis的安装配置
codis是分布式redis解决方案 centos系统下安装codis需要安装相关的依赖,将图中的依赖上传至centos系统中 依次进行安装: 一.go环境的安装配置 解压到install目录下: . ...
- 在搭建Hadoop集群环境时遇到的一些问题
最近在学习搭建hadoop集群环境,在搭建的过程中遇到很多问题,在这里做一些记录.1. SSH相关的问题 问题一: ssh: connect to host localhost port 22: Co ...