MySQL数据库连接驱动8.X版本引起的时区问题
运行报错:
java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone…..
错误原因:time zone 时区错误。
解决方式一
1.在连接MySQL的 url后面加上时区:
?serverTimezone=GMT //或者UTC 注:GMT%2B8:中国时区UTC:国际标准时区
解决方式二
1.使用root用户登录mysql
2.查看时区:show variables like '%time_zone%';注:system_time_zone是值是SYSTEM(美国时间,中国要迟8小时)
3.时区设置为当前系统时区即可,采用+8:00格式:set global time_zone='+8:00';
解决方式三
1.修改mysql的my.cnf配置文件,在[mysql]下面添加: default-time-zone=’+08:00’
注:新版本的Driver不再使用com.mysql.jdbc.Driver,需要使用新的com.mysql.cj.jdbc.Driver