You must configure either the server or JDBC driver (via the serverTimezone configuration property)

2020-06-24 10:16:41

参考连接 You must configure either the server or JDBC driver (via the serverTimezone configuration property)

JDBC使用8.0驱动包连接mysql设置时区serverTimezone

驱动包用的是新版 mysql-connector-java-8.0.16.jar
新版的驱动类改成了com.mysql.cj.jdbc.Driver
新版驱动连接url也有所改动
I、指定时区

如果不设置时区会相差13个小时
比如在java代码里面插入的时间为:2019-07-26 19:28:02
但是在数据库里面显示的时间却为:2019-07-26 06:28:02

所以使用上海时间(注意:没有asia/beijing时区)
serverTimezone=Asia/Shanghai

II、指定是否用ssl连接,true值还报错了
useSSL=false

完整代码:

url=jdbc:mysql://ip:port/xxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&useSSL=false
driverClassName=com.mysql.cj.jdbc.Driver

 



  • 2017-12-05 22:30:02

    php7.0升级php7.2

    看电脑上的教程要备份7.0配置文件以及扩展啥的,我感觉不如卸载干净重新安装

  • 2017-12-06 09:35:10

    分页优化的四种方式

    在大数据量的情况下,原本很简单的分页如果没有处理好,你会发现分页的请求会消耗你大量的数据库时间。如果你遇到了这个问题,文章给了你几个很好的解决的方案。当然,初学者若能看完这篇文章,那么它会指导你写出更具有扩展性的分页代码。