运行
java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

初步判断是驱动的问题,在pom.xml上设置版本号(很多都是5.7版本,现在大多是8.0版本)
<!--Mysql-->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
<version>8.0.31</version>
</dependency>

再次启动依然报错,于是仔细查看后发现是application.yml的URL配置有误,
create connection SQLException, url: jdbc:mysql://localhost:3306/enterprise_digital?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai, errorCode 0, state 08001
之前用的数据库是网络公共的,后来用的自己的数据库更改了相关配置,多加了东西,改正过来即可正常使用
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/enterprise_digital?serverTimezone=UTC&serverTimezone=Asia/Shanghai
username: root
password: 123321


文章讲述了在运行Java应用时遇到SQL连接异常的问题,问题根源在于MySQL驱动版本不匹配以及application.yml中的URL配置错误。通过更新pom.xml中MySQL驱动的版本到8.0.31,并修正URL参数,特别是去除不恰当的公共数据库相关配置,解决了连接问题。最终成功配置包括Druid数据源、驱动类名、URL、用户名和密码。
1286

被折叠的 条评论
为什么被折叠?



