当前位置:   article > 正文

spring boot连接mysql8.0

springboot jar 打包是mysql5.7,发联到mysql8.033

今天spring boot的项目数据库从mysql5.7换到mysql8.0,遇到点问题,特此记录下来

查看mysql的版本

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

修改mysql的依赖使用MySQL Connector/J

<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

项目启动如果报错

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

修改数据源配置

# 数据源配置,请修改为实际配置
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

如果报错 

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

连接数据库的url中,加上allowPublicKeyRetrieval=true参数

 

转载于:https://www.cnblogs.com/baby123/p/11419957.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/988925
推荐阅读
相关标签
  

闽ICP备14008679号