springboot 2.1.1版本数据库连接不上,报了一个错误:
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: jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
最后的serverTimezone=GMT%2B8就是时区设置。
设置完成之后就可以正常启动了!
完整的配置:
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
driver-class-name: com.mysql.cj.jdbc.Driver
注意com.mysql.cj.jdbc.Driver是mysql5.6以后版本的数据库驱动。