SpringBoot数据库配置报错
SpringBoot在连接数据库的时候会出现如下报错,原因是时间区域时差问题
java.sql.SQLException: 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.
这时候需要在配置数据库的url后面加上
serverTimezone=GMT%2B8
UTC代表的是全球标准时间 ,但是我们使用的时间是北京时区也就是东八区,领先UTC八个小时
# 连接四大参数
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
# 可省略,SpringBoot自动推断
spring.datasource.driver-class-name=com.mysql.jdbc.Driver