原jdbc url
url: jdbc:mysql://localhost:3306/renren_security?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
修改后
url: jdbc:mysql://localhost:3306/renren_security?useSSL=false&useUnicode=true&characterEncoding=utf-8&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
区别在于添加了
useLegacyDatetimeCode=false&
MySQL8.0
1 8.0驱动里没有userLegacyDatetimeCode和userTimezone两个参数
2 一定要配置serverTimezone为MySQL运行的时区. 连接建立时会将这个时区存储到连接中. 见NativeProtocol#2147#2158
3 将年月日时分秒+"配置时区"构造时间戳. 见SqlTimestampValueFactory#100. 这里的cal就是在#68根据"配置时区"创建的
基本问题
0.1 MySQL驱动5.1有userLegacyDatetimeCode和userTimezone两个参数, 8.0没有
0.2 Java与MySQL间传递时间戳的时候, 传递的是年月日时分秒, 没有时区
0.3 MySQL传递回来的是: MySQL读取到底层存储的时间戳, 按照当前连接(MySQL侧)的时区转为年月日时分秒
0.4 但是, 两个系统时区可能会不同, userLegacyDatetimeCode和userTimezone就是用来协调时区的
引用转载
两种解决异常:“The last packet sent successfully to the server was 0 milliseconds ago. ”的办法_云枫的专栏-CSDN博客出现异常”The last packet sent successfully to the server was 0 milliseconds ago.“的大部分原因是由于数据库回收了连接,而系统的缓冲池不知道,继续使用被回收的连接所致的。 以mysql为例: 第一种解决办法,就是将mysql回收空闲连接的时间变长,mysql默认回收时间是8小时,可https://blog.csdn.net/shiqidide/article/details/7642531第二页评论 不停奔跑 的回答