SpringBoot连接数据库项目运行报错:Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException

标题Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException

SpringBoot+mybatis(或hibernate)连接数据库时报错,application.properties中的配置信息都是按照书本上的正常配置,但是就是报错,具体如下图:
SpringBoot连接数据库项目运行报错:Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException_第1张图片百度+Google很久之后才找到解决方案,其实这不是本身项目的错误,而是版本的不一致问题,为了使MySQL JDBC驱动程序的5.1.33版本与UTC时区配合使用,就需要在配置文件中数据库连接后面指定serverTimezone,代码如下:

1、spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC
2、jdbc:mysql://localhost:3306/lovewhf?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
//其中1是解决上面的所说的问题,在后面指定serverTimezone即可,2是更加详细的配置,包含解码、时区等配置。

你可能感兴趣的:(SpringBoot)