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. 002-poi-excel-导出设置单元格数据校验规则、筛选功能

    一.数据验证概述 推荐以下操作在2007之后操作 1.1.查看excel的数据验证 1.进入 2.设置规则 通过验证条件允许,可以看到是每个单元格默认只成立一种条件 1.2.POI代码开发-数据验证 ...

  2. confluent kafka connect remote debugging

    1. Deep inside of kafka-connect start up To begin with, let's take a look at how kafka connect start ...

  3. IE和火狐的css兼容性问题

     CSS对浏览器器的兼容性具有很高的价值,通常情况下IE和Firefox存在很大的解析差异,这里介绍一下兼容要点. 1.DOCTYPE 影响 CSS 处理 2.FF: div 设置 margin-le ...

  4. 【Leetcode_easy】720. Longest Word in Dictionary

    problem 720. Longest Word in Dictionary 题意: solution1: BFS; class Solution { public: string longestW ...

  5. Vue + GraphQL初试

    基本用法 GraphQL概述 GraphQL基本语法特性 GraphQL类型系统 GraphQL类型系统内置基础类型 GraphQL类型系统内置修饰符 GraphQL工作原理 GraphQL执行过程 ...

  6. 利用 AWS 无服务架构之语音合成

    目录 一.架构图 二.服务部署 2.1.创建 DynamoDB 表 2.2.创建 S3 2.2.1 静态网页存储桶 2.2.2.音频存储桶 2.3.创建 SNS Topic 2.4.为 Lambda ...

  7. Windows Server 2012 R2蓝屏

    最近发现某个医院客户Windows Server 2012 R2 DataCenter的系统频繁蓝屏重启,重启没过一天再一次出现,反反复复折腾好几天,提示信息ntoskrnl.exe.mssmbios ...

  8. Flarum 安装问题 编译安装 fileinfo.so

    大部分人上传 会遇到文件没有权限这一问题 ,这个好解决 下边是服务器 php.ini 扩展 fileinfo 由于php 版本是7.1.8 最新的 又是用的一键环境安装 所以 没有安装这个扩展 1.去 ...

  9. 记录项目中easyui的运用

    1.实现合并列,且文字显示居左,背景为固定颜色 效果图: 实现代码: $('#tab').datagrid({ title : '', //表格标题 iconCls : 'icon-list', // ...

  10. Jenkins持续集成企业实战

    阅读目录: Jenkins持续集成企业实战1.1 目前主流网站部署的流程1.2 Jenkins持续集成简介1.3 Jenkins持续集成组件1.4 Jenkins平台安装部署1.5 Jenkins相关 ...