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 ifc数据渲染着色器
//顶点着色器 static const char* vertShader = { "varying vec4 color;\n" "void main(void)\n& ...
- 36 Flutter仿京东商城项目 用户登录 退出登录 事件广播更新状态
Login.dart import 'dart:convert'; import 'package:dio/dio.dart'; import 'package:flutter/material.da ...
- Qt编写自定义控件37-发光按钮(会呼吸的痛)
一.前言 这个控件是好早以前写的,已经授权过好几个人开源过此控件代码,比如红磨坊小胖,此控件并不是来源于真实需求,而仅仅是突发奇想,类似于星星的闪烁,越到边缘越来越淡,定时器动态改变边缘发光的亮度,产 ...
- web端安全测试工具
https://www.cnblogs.com/ios9/p/7692373.html 十大web安全扫描工具 扫描程序可以在帮助造我们造就安全的Web 站点上助一臂之力,也就是说在黑客“黑”你之前, ...
- PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)
1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime ...
- EasyNetQ使用(六)【多态发布和订阅,消息版本控制】
你能够订阅一个接口,然后发布基于这个接口的实现. 让我们看下一个示例.我有一个接口IAnimal和两个实现Cat和Dog: public interface IAnimal { string Name ...
- 2019-10-24 李宗盛 spss作业
3.1数据排序. 在统计分析时最初的变量. 可能不符合统计分析的要求,需要用户对目标数据进行整理,来符合分析方法个案排序.数据——个案排序.排序依据,排序顺序,变量排序 数据——变量排序 变量视图 ...
- 移动架构-json解析框架
JSON在现在数据传输中占据着重要地位,相比于xml,其解析和构成都要简单很多,第三方的解析框架也不胜枚举,这里之所以要自定义一个json解析框架,一方面是更好的了解json解析过程,另一方面是有时候 ...
- MyBatis框架总结
一. MyBatis简介 MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架.MyBatis 消除 了几乎所有的 JDBC 代码和参数的手工设置以及结果集的检索.MyBati ...
- JRE和JDK的作用和区别
JVM(Java Virtual Machine)是一个虚拟的用于执行bytecode字节码的“虚拟计算机”JRE(Java Runtime Environment):Java 虚拟机.库函数 ...