mysql 8.0 解决报错Public Key Retrieval is not allowed

项目中数据库mysql从5.7升到8.0后启动报错:java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

经过查找文档,找到两个属性

  • serverRSAPublicKeyFile

    File path to the server RSA public key file for sha256_password authentication. If not specified, the public key will be retrieved from the server.

    Since Version5.1.31
  • allowPublicKeyRetrieval

    Allows special handshake round-trip to get an RSA public key directly from server.

    Default Valuefalse
    Since Version5.1.31

serverRSAPublicKeyFile:放置服务器上的公钥文件位置

 allowPublicKeyRetrieval:允许从服务器上获取公钥

Note

To authenticate accounts with the caching_sha2_password plugin, either a secure connection to the server using SSL or an unencrypted connection that supports password exchange using an RSA key pair (enabled by setting one or both of the connecting properties allowPublicKeyRetrieval and serverRSAPublicKeyFile) must be used.

大致意思是说使用caching_sha2_password插件的,这两个属性必须要设置一个。

If the MySQL server's default authentication method was SHA256 but neither one of the Connector/J connection properties allowPublicKeyRetrieval and serverRSAPublicKeyFile was set, the authentication failed with a TransientConnectionException, complaining that the public key could not be retrieved. With this fix, authentication continues in the situation, allowing other enabled authentication methods to be tried. (Bug #20433047, Bug #75670)

 如果两个都没有设置,会抛public key could not be retrieved异常。

经过在网上搜索和查文档有两个解决方法:

1. 将allowPublicKeyRetrieval设为true,允许从服务器上获取公钥文件

jdbcUrl=jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true

2. 设置公钥文件位置serverRSAPublicKeyFile:

将服务器上数据目录下的public_key.pem拷至本地,连接上加上此属性 serverRSAPublicKeyFile=/data%2Fpublic_key.pem, 文件:/data/public_key.pem, %2F为/,%3A为:

jdbcUrl=jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=GMT%2B8&serverRSAPublicKeyFile=/data%2Fpublic_key.pem

 以上两种方法都可以解决。

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值