Tomcat启动报:The Server time zone value 'XXXXX' 乱码问题解决

今天给自己项目打包到服务器发布时,运行时,发现报

java.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.

错误

经过查询资料发现是

MySql本身的时区设置的问题导致的


解决办法:

方法一:

1.在mysql安装位置下找到my.ini文件;

2.修改my.ini文件中:在[mysqld]下方,添加

default-time-zone='+08:00'

3.重启即可

 

方法二:

我是springboot项目,使用tomcat发布时报的,可以使用一下方法解决

在你项目的数据库配置url位置,后面加上 serverTimezone=UTC

jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

如果发现新加数据比当前时间少8个小时,或者查询显示出来的数据比数据库入库的时间多8个小时,可以改为:serverTimezone=GMT%2B8

这样新添加的数据为正常时间


结束

posted @ 2019-08-23 16:43  丿似锦  阅读(1685)  评论(0编辑  收藏  举报