maven管理springboot项目切换mysql server8

原springboot项目使用的mysql5,如今切换到mysql8需修改三个地方

  • maven中的pom.xml需将mysql连接驱动修改为8版本


  mysql
  mysql-connector-java
  5.1.37

修改为8:


  mysql
  mysql-connector-java
  8.0.11
  • 数据库连接url中添加时区serverTimezone=GMT​​​​​​以及useSSL=true

在application-dev.yml添加如下:

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/blog?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT&useSSL=true
    username: root
    password: 123456
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
  • jpa中添加database-platform

springboot启动失败的问题('hibernate.dialect' not set)

原因是Hibernate SQL方言没有设置,在properties文件中增加下面这行:

database-platform: org.hibernate.dialect.MySQL5Dialect

如果配置文件格式为application.yml,则在JPA配置中添加以下代码:

database-platform: org.hibernate.dialect.MySQL5Dialect,如下图:

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/blog?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT
    username: root
    password: 123456
  jpa:
    database-platform: org.hibernate.dialect.MySQL5Dialect
    hibernate:
      ddl-auto: update
    show-sql: true

 

你可能感兴趣的:(Java旅程,maven,springboot,mysql8)