报错介绍
将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的话加不加都可以
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。