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 ...
随机推荐
- 25.Flutter中的表单 Radio RadioListTile Switch SwitchListTile 以及表单组件实现一个简单的学员登记系统(下)
四.Radio.RadioListTile单选按钮组件 Radio常用属性: value单选的值. onChanged改变时触发. activeColor:选中的颜色.背景颜色 groupValue: ...
- EasyUI动态展示用户信息
业务需求:用户登录后展示用户名.用户对应的角色.EasyUI只不过是一个前端的框架,封装了一些组件和样式,你可以用jsp直接调后台获取到用户信息展示,但我这里想用html页面,用目前流行的说法:前后端 ...
- robot用例执行常用命令(还没试)
执行命令 执行一个用例 robot -t “testcase_name“ data_test.robot 按用例文件执行 robot data_test.robot或者robot --suite “p ...
- 安装git和关联gitlab拉取代码步骤
1.双击 “Git-2.9.2-64-bit.exe”文件,一路next安装git程序 2.为github帐号添加SSH keys 3.使用git clone命令从GitLab上同步代码库时,如果使用 ...
- LeetCode_21. Merge Two Sorted Lists
21. Merge Two Sorted Lists Easy Merge two sorted linked lists and return it as a new list. The new l ...
- (十六)集合框架(Collection和Map)和比较器(Comparable和comparator)
一.集合框架 1.1 为什么要使用集合框架? 当我们需要保持一组一样(类型相同)的元素的时候,我们应该使用一个容器来保存,数组就是这样一个容器. 那么,数组的缺点是什么呢? 数组一旦定义,长度将不能再 ...
- (十三)过滤器Filter(转)
--------转自孤傲苍狼博客 一.Filter简介 Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例 ...
- php注册自动加载函数
$autoload_func = function($class) { $class = str_replace('\\', '/', $class); $file_name = dirname(__ ...
- js 高级程序设计 第四章学习笔记
问题:怎么才能形象的理解堆栈空间? 1. 声明变量 使用 var 声明的变量会自动被添加到最接近的环境中.在函数内部,最接近的环境就是函数的局部 环境:在 with 语句中,最接近的环境是函数环境.如 ...
- Pyhthon3之使用__slots__
正常情况下,我们定义了一个class,创建了一个class实例后,我们可以给该实例绑定任何属性和方法,这就是动态语言的灵活性.先定义class: >>> class Student( ...