社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
1. Java 数据库连接使用 UTC 时区(世界标准时间),即 serverTimezone=UTC,而北京时间比 UTC 时间早8小时,即 UTC+08:00,如果我们直接使用 serverTimezone=UTC,写入数据库中的数据会提前 8 个小时。
使用数据库MySQL8.0就必须需要时区这些配置
spring:
application:
name: fileupload
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/csdw?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
username: root
password: 11111
注意这一句中的serverTimezone=UTC
url: jdbc:mysql://localhost:3306/csdw?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
url: jdbc:mysql://localhost:3306/csdw?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!