前言
今天把数据库版本从5.7升级到8.0后,启动springboot项目时报如下错误
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.
这样的问题,怎么解决,下面提供几种解决方案
解决方案
首页,把驱动版本进行升级,如下
把com.mysql.jdbc.Driver 换成 com.mysql.cj.jdbc.Driver
- 方案一,直接通过数据库命令修改(不推荐使用,数据库服务重启就没了)
通过客户端连接到数据库后,执行如下命令 - 方案二,修改连接配置文件
在yml文件增加serverTimezone=Asia/Shanghai;
jdbcUrl: jdbc:mysql://192.168.101.30:3306/qjjs_opss_web?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
- 方案三,修改my.ini文件
找到mysql的配置文件,添加:default-time-zone=’+08:00’,如图
最后重启mysql服务。
写在最后
这里不推荐使用第一种方案,因为数据库重启后,就恢复到原来的状态了,用于测试环境还可以,在大家升级数据库的时候,注意时区这个问题就好了。。
如果想要了解更多知识,请及时关注我吧_