启动java项目mysql8数据库报时区The server time zone错误

报错介绍

将Mysql5.6版本升级到8.0.12版本后,Java在访问Mysql数据库时出现如下异常:

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.

解决方案

mysql8与mysql5除了链接驱动不一样外,url也有一个必须要带有的参数,那就是时区参数serverTimezone,参数值可以是Asia/Shanghai 或者GMT%2B8或者UTC ,根据自己的情况来选择,通常第一个即可,数据库链接url信息参考如下

jdbc.url=jdbc:mysql://localhost:3306/数据库名?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai

mysql8配置上时区参数后就不会再报时区The server time zone…的问题了,mysql5的话加不加都可以

© 版权声明
THE END
喜欢就支持一下吧
点赞0赞赏 分享