现在很多项目mysql都升级到了8.0以上版本,那么对应的springboot配置文件也要修改
<!-- 引入Spring封装的jdbc,内部默认依赖了 HikariDataSource 数据源-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<!-- web项目启动模块-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- mysql数据库连接驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>8.0.16</version>
</dependency>
高版本的 spring boot 搭配 mysql 8.x驱动版本较高时,如 mysql-connector-java:8.0.16,此时 driver-class-name 的值要带 cj;url 的值要带时区 serverTimezone,如:
spring:
datasource:url: jdbc:mysql://127.0.0.1:3306/test?characterEncoding=UTF-8&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver