报错
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 Connector/J 6.x以上的版本,然后就报了时区的错误
遇到的问题 servertime=UTC导致时间差8个小时(
MySQL jdbc 6.0 版本以上必须配置此参数
)
解决办法
在配置url的时候不能简单写成 :
jdbc:mysql://localhost:3306/mysql
而是要写成 :
jdbc:mysql://localhost:3306/mysql?serverTimezone=UTC
- 虽然上面加上时区程序不出错了,但是我们在用java代码插入到数据库时间的时候却出现了问题。
比如在java代码里面插入的时间为:2017-08-21 17:29:56
但是在数据库里面显示的时间却为:2017-08-21 09:29:56
因为时区设置的问题。
UTC代表的是全球标准时间 ,但是我们使用的时间是北京时区也就是东八区,领先UTC八个小时。
UTC + (+0800) = 本地(北京)时间
解决方案
url的时区使用中国标准时间。也是就
serverTimezone=Asia/Shanghai
本文详细解析了在使用MysqlConnector/J6.x版本时遇到的时区配置问题,特别是servertime=UTC导致的时间偏差。提供了正确的URL配置方法,如使用serverTimezone=Asia/Shanghai来确保数据正确插入。
438

被折叠的 条评论
为什么被折叠?



