错误日志:com.zaxxer.hikari.pool.HikariPool : HikariPool-3 - Exception during pool initialization. java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
程序使用了 HikariCP 作为连接池,HikariCP 在启动时尝试初始化数据库连接,但因为 JDBC URL 配置中没有启用 allowPublicKeyRetrieval=true
,MySQL 拒绝了连接请求。
方法一加上这个配置:
spring.datasource.url=jdbc:mysql://localhost:3306/testdb?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=your_password
如果你使用 application.yml
,配置如下:
spring:
datasource:
url: jdbc:mysql://localhost:3306/testdb?useSSL=false&allowPublicKeyRetrieval=true
username: root
password: your_password
方法二直接重启idea重新运行就成功了