数据库默认的时区不同,存取时间相关数据时会有偏差
下面为几种修改方式
1、mysql命令配置时区
show variables like "%time_zone%";
set global time_zone = "+8:00";
set time_zone = '+8:00';
flush privileges;
show variables like "%time_zone%";
注:这种修改在重启数据库后,会恢复成默认时区
2、配置jdbc链接
增加参数serverTimezone=GMT%2B8
spring.datasource.url: jdbc:mysql://localhost:3306/springboot_demo?serverTimezone=GMT%2B8&useUn
3、修改mysql配置
修改 /etc/mysql/my.cnf
增加参数
default-time-zone='+08:00'
阿里云配置修改
注意这里是
+8:00
查看结果