MySQL从数据库中查询出的数据与数据库中的值不对

版权声明:本文为博主原创文章,用来记录学习过程,欢迎交流学习。 https://blog.csdn.net/k_young1997/article/details/89607324

今天在测试项目时发现从数据库中获取出的时间比数据库中的值晚了八个小时。错误如下:

数据库中的数据:

在这里插入图片描述

实际查询出的数据(因为是根据条件查询,顺序不一致,可能有些没有显示):

在这里插入图片描述

解决办法:

原因是:serverTimezone=UTC

jdbc:mysql://localhost:3306/db_shop?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8

将其改为:serverTimezone=Asia/Shanghai 即可

spring.datasource.url=jdbc:mysql://localhost:3306/db_shop?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8

猜你喜欢

转载自blog.csdn.net/k_young1997/article/details/89607324