MySQL8 提示Public Key Retrieval is not allowed错误解决方法

1,516 阅读1分钟

造成原因

如果用户使用了 sha256_password 认证,密码在传输过程中必须使用 TLS 协议保护,但是如果 RSA 公钥不可用,可以使用服务器提供的公钥;可以在连接中通过 ServerRSAPublicKeyFile 指定服务器的 RSA 公钥,或者AllowPublicKeyRetrieval=True参数以允许客户端从服务器获取公钥;但是需要注意的是 AllowPublicKeyRetrieval=True可能会导致恶意的代理通过中间人攻击(MITM)获取到明文密码,所以默认是关闭的,必须显式开启。

dbeaver客户端

连接设置-->驱动属性-->修改AllowPublicKeyRetrieval=True image.png

程序驱动连接

配置驱动url添加

allowPublicKeyRetrieval=true&useSSL=false

如:

jdbc:mysql://localhost:3306/mysql?allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8