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性能监控 -CPU、Memory、IO、Network等指标的讲解

    [操作系统-linux]linux性能监控 -CPU.Memory.IO.Network等指标的讲解(转) 一.CPU 1.良好状态指标 CPU利用率:User Time <= 70%,Syst ...

  2. 5G && 物联网

    可打电话的 2G.能够上网的 3G.满足移动互联网用户需求的 4G 相比,逐步可以商用的 5G 在多重性能上更胜一筹,如 高数据率: 低延迟: 更节能: 有效地降低通信成本: 具备更高的系统容量: 更 ...

  3. LeetCode_125. Valid Palindrome

    125. Valid Palindrome Easy Given a string, determine if it is a palindrome, considering only alphanu ...

  4. (十四)用session和过滤器方法检验用户是否登录

    一.session方法 1.1 编写登录页面文件(index.html) <!doctype html> <html> <head> <title>测试 ...

  5. Win10使用Tex Live和VS Code和Latex Workshop插件编写Latex文档(未完成版本)

    首先取Tex Live官网下载安装包:https://www.tug.org/texlive/acquire-netinstall.html 我下载的是 http://mirror.ctan.org/ ...

  6. jqGrid获取展示的所有行id集合

    $("#jqGrid").getDataIDs();

  7. js时间戳与日期格式之间相互转换

    ###js时间戳与日期格式之间相互转换 将时间戳转换成日期格式 // 简单的一句代码 var date = new Date(时间戳); //获取一个时间对象 /** 1. 下面是获取时间日期的方法, ...

  8. 串口(USART)通信-串口通讯协议简介

    物理层:规定通讯系统中具有机械.电子功能部分的特性,确保原始数据在物理媒体的传输.其实就是硬件部分. 协议层:协议层主要规定通讯逻辑,统一收发双方的数据打包.解包标准.其实就是软件部分. 简单来说物理 ...

  9. 初始STM32固件库

    1-汇编编写的启动文件 startup_stm32f10x_hd.s:设置堆栈指针.设置PC指针.初始化中断向量表.配置系统时钟.对用C库函数_main,最终去到C的世界 2-时钟配置文件 syste ...

  10. goroutine基础

    程序1: package main import ( "fmt" "time" ) func test () { var i int for { fmt.Pri ...