spring boot鏈接mysql8.0

今天spring boot的項目數據庫從mysql5.7換到mysql8.0,遇到點問題,特此記錄下來java

查看mysql的版本mysql

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.12 |
+-----------+spring

修改mysql的依賴使用MySQL Connector/Jsql

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.12</version>
</dependency>

數據源配置數據庫

# 數據源配置,請修改成實際配置
spring.datasource.url=jdbc:mysql://localhost:3306/bim?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&failOverReadOnly=false
spring.datasource.username=bimengine
spring.datasource.password=fgBQLZpgDaxH7xuu
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

項目啓動若是報錯url

java.sql.SQLException: The connection property 'zeroDateTimeBehavior' acceptable values are: 'CONVERT_TO_NULL', 'EXCEPTION' or 'ROUND'. The value 'convertToNull' is not acceptable.spa

修改數據源配置code

# 數據源配置,請修改成實際配置
spring.datasource.url=jdbc:mysql://localhost:3306/bim?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=CONVERT_TO_NULL&autoReconnect=true&useSSL=false&failOverReadOnly=false
spring.datasource.username=bimengine
spring.datasource.password=fgBQLZpgDaxH7xuu
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

若是報錯 server

java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not alloweblog

鏈接數據庫的url中,加上allowPublicKeyRetrieval=true參數

相關文章
相關標籤/搜索