com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Public Key Retrieval is not?

发布时间 2023-10-30 17:07:38作者: 尐鱼儿

问题 :连接MySQL数据库时抛出异常信息: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Public Key Retrieval is not allowed
一开始aplication.yml配置如下所示:

spring:
application:
name: service-provider-sentinel9999
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/gwmdb?useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: root
password: root

 

后来找了一些解决方案,发现是MySQL 8.0版本导致的问题,需要在后面加 allowPublicKeyRetrieval=true,如下所示:

spring:
application:
name: service-provider-sentinel9999
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/gwmdb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true
username: root
password: root

 

然后重新启动服务即可!