SpringBoot连接MySQL

  • 需要导入的依赖

  • <!--这是直接在创建springboot项目时直接勾选生成的-->
    <!--jdbc-->
    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <!--mysql-->
    <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
       <scope>runtime</scope>
    </dependency>

1. MySQL 8

yaml配置:


spring:
datasource:
  username: root
  password: root
  url: jdbc:mysql://localhost:3306/mybatis_plus?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
  driver-class-name: com.mysql.cj.jdbc.Driver

2. MySQL 5

yaml配置:

spring:
datasource:
  username: root
  password: root
  url: jdbc:mysql://localhost:3306/mybatis_plus?useSSL=false&useUnicode=true&characterEncoding=utf-8
  driver-class-name: com.mysql.jdbc.Driver