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. osg fbx模型删除模型中的某几个节点,实现编辑模型的功能

    fbx model element count:80 三维视图: {三维} 4294967295 osg::MatrixTransform1 基本墙 wall_240 [361750] 4294967 ...

  2. Kafka Connect Architecture

    Kafka Connect's goal of copying data between systems has been tackled by a variety of frameworks, ma ...

  3. mysql为字段添加或删除自增属性

    删除自增属性: ALTER TABLE `members` CHANGE uid uid INT(10) UNSIGNED NOT NULL ; 添加自增属性: ALTER TABLE `member ...

  4. 转载【oracle切换表空间】

    http://blog.itpub.net/28939273/viewspace-1061476/ [root@yoon ~]# more /etc/oracle-releaseOracle Linu ...

  5. Azure DevOps 利用rest api设置variable group

    我们在Azure DevOps中设置参数的时候,可以使用build,release各自的variables,但是各自的变量不能共用.此时我们需要使用variable group,它允许跨Build和R ...

  6. LNMP V1.4正式版本安装及新增Let's Encrypt一键安装和其他功能

    军哥的LNMP一键安装包已经有一些年头了,着实给需要在Linux VPS.服务器中安装WEB环境的用户提供不小的帮助,而且每年儿童节都会有较大版本的更新和升级.老左在二月份的时候有体验过LNMP V1 ...

  7. Pychar调用远程编译器的环境配置

    版本:2019最新专业版

  8. 使用Rabbit MQ消息队列

    使用Rabbit MQ消息队列 综合概述 消息队列 消息队列就是一个消息的链表,可以把消息看作一个记录,具有特定的格式以及特定的优先级.对消息队列有写权限的进程可以向消息队列中按照一定的规则添加新消息 ...

  9. cocos creator 判断滑动方向

    定义变量 public firstX = null; public firsty = null; 点击 获取坐标 this.viewNode.on(cc.Node.EventType.TOUCH_ST ...

  10. docker下部署服务

    一.zabbix部署 需求: 因最近项目过多,人力监控耗费时间,打算部署一个zabbix,但又不想部署在宿主机上,就想起了docker,docker快速的移植性是最大的亮点,好了,言归正传开始干. 部 ...