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的更多相关文章

  1. 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 ...

  2. 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= ...

  3. java连接mysql出现The server time zone value '�й���׼ʱ��' is unrecognized or represents more than...

    在连接的配置文件中,指定数据库位置的末尾加上serverTimezone=UTC ```yml url: jdbc:mysql://localhost:3306/app?serverTimezone= ...

  4. [bug]mysql: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone

    原因: 时区设置有误 解决: 在mysql中修改时区设置: 或 在JDBC代码中增加时区设置: Connection c = DriverManager.getConnection("jdb ...

  5. mysql的时区错误问题,The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one

    在使用springboot整合ssm和druid的时候出现数据库一个问题 org.springframework.web.util.NestedServletException: Request pr ...

  6. 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 ...

  7. 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 ...

  8. Eclipse连接MySQL出现Server time zone is unrecognized错误

    错误代码: The server time zone value '?й???????' is unrecognized or represents more than one time zone. ...

  9. MySQL连接数据库报时区错误:java.sql.SQLException: The server time zone value

    连接MySQL数据库时报以下时区错误信息: java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized ...

随机推荐

  1. Linux 验证当前 Video0 不否是v4l设备 linux v4l 编程(1) Video 4 Linux 简介

    #include <stdio.h> #include <string.h> #include <errno.h> #include <sys/types.h ...

  2. 《海会圣贤》高清字幕版(由香港佛陀教育协会发布DVD恭敬转成)

    常念阿彌陀佛 2015-09-22 视频(建议WIFI下收看)时长72分钟 https://v.qq.com/x/page/f0166amk57h.html 香港佛陀教育协会发布DVD   DVD+高 ...

  3. Oracle中查询当前时间、时间格式化方法

    Oracle中如何获取系统当前时间 select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;  ORACLE里获取一个时间的年.季.月.周. ...

  4. git clone时加上--depth 1

    当项目过大时,git clone时会出现error: RPC failed; HTTP curl The requested URL returned error: Gateway Time-out的 ...

  5. Xena L23网络测试仪Valkyrie使用技巧100例,目录

    Xena L23网络测试仪Valkyrie使用技巧100例,先写个目录 100例,会不会有点多,写不完... ^_^ 第1次编辑于2019-11-27 22:05:52, Evan YE. 编号 标题 ...

  6. Egret入门学习日记 --- 第十八篇(书中 8.5~8.7 节 内容)

    第十八篇(书中 8.5~8.7 节 内容) 其实语法篇,我感觉没必要写录入到日记里. 我也犹豫了好久,到底要不要录入. 这样,我先读一遍语法篇的所有内容,我觉得值得留下的,我就录入日记里. 不然像昨天 ...

  7. 关于一些初学Unity的基本操作和自己的理解

    1.Scene面板操作:  A.按住鼠标右键,拖动鼠标,可以旋转  B.鼠标滚轮前后滑动,前进后退  C.按下鼠标滚轮,拖动鼠标,可以拖动场景  D.在场景中选中物体,按F键或者在Hierarchy面 ...

  8. 判断scrollView的滑动方向(二)

    在上一篇文章<判断scrollView的滑动方向>中谈到的第二种方法是根据滑动速率来判断的. 今天将通过滑动过程中的坐标差来判断 - (void)scrollViewDidScroll:( ...

  9. python lanbda匿名函数(20)

    在python开发中常规的函数在调用之前都需要先声明,而python还有一种匿名函数,有速写函数的功能并且匿名函数不需要声明也没有函数名字,完全不需要担心函数名冲突,具体的妙用还需要从实战练习中多多积 ...

  10. Win10下 jdk的安装

    jdk 的下载地址 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 在 D 盘 ...