本地主机远程连接MySQL8.0数据库出现错误Public Key Retrieval is not allowed

当使用MySQL Connector尝试远程连接MySQL数据库时,如果遇到PublicKey Retrieval is not allowed错误,意味着客户端需要允许从服务器自动获取RSA公钥。可以通过设置连接字符串中的AllowPublicKeyRetrieval=True来解决这个问题。但要注意,这可能导致中间人攻击风险,因此默认设置为False。确保在了解潜在安全风险后才启用此选项。
摘要由CSDN通过智能技术生成

本地主机远程连接MySQL数据库出现错误Public Key Retrieval is not allowed

文档中(https://mysql-net.github.io/MySqlConnector/connection-options/)给出的解释是

AllowPublicKeyRetrieval,允许公用密钥检索

If the user account uses sha256_password authentication, the password must be protected during transmission; TLS is the preferred mechanism for this, but if it is not available then RSA public key encryption will be used. To specify the server’s RSA public key, use the ServerRSAPublicKeyFile connection string setting, or set AllowPublicKeyRetrieval=True to allow the client to automatically request the public key from the server. Note that AllowPublicKeyRetrieval=True could allow a malicious proxy to perform a MITM attack to get the plaintext password, so it is False by default and must be explicitly enabled.
翻译如下:
如果用户帐户使用sha256_password身份验证,则在传输过程中必须保护密码。TLS是实现此目的的首选机制,但是如果它不可用,则将使用RSA公钥加密。要指定服务器的RSA公钥,请使用ServerRSAPublicKeyFile连接字符串设置,或设置AllowPublicKeyRetrieval=True为允许客户端自动从服务器请求公钥。请注意,这AllowPublicKeyRetrieval=True 可能允许恶意代理执行MITM攻击以获取纯文本密码,因此False默认情况下必须启用它,并且必须显式启用它。

所以只要在创建连接时候修改驱动属性:AllowPublicKeyRetrieval为True

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,下面是如何使用 Docker Compose 安装 MySQL 8.0 并解决 "Public Key Retrieval is not allowed" 报错问题的步骤: 1. 首先,创建一个名为 `docker-compose.yml` 的文件,并在其中添加以下内容: ```yaml version: '3' services: db: image: mysql:8.0 command: --default-authentication-plugin=mysql_native_password restart: always environment: MYSQL_ROOT_PASSWORD: your_root_password ports: - 3306:3306 ``` 请将 `your_root_password` 替换为你想要设置的 MySQL root 用户密码。 2. 保存并关闭 `docker-compose.yml` 文件。 3. 打开终端或命令提示符,进入包含 `docker-compose.yml` 文件的目录。 4. 运行以下命令启动 MySQL 容器: ``` docker-compose up -d ``` 这将下载并启动 MySQL 8.0 容器。 5. 当容器成功启动后,你可以使用以下命令检查容器的状态: ``` docker-compose ps ``` 你应该看到一个名为 `db` 的容器正在运行。 6. 如果你遇到 "Public Key Retrieval is not allowed" 报错问题,请尝试使用以下命令进入 MySQL 容器: ``` docker exec -it <container_id> bash ``` 请将 `<container_id>` 替换为实际的容器 ID。可以通过运行 `docker ps` 命令来获取容器 ID。 7. 在进入容器的终端后,使用以下命令连接到 MySQL 服务器: ``` mysql -u root -p ``` 然后输入之前在 `docker-compose.yml` 文件中设置的 MySQL root 用户密码。 8. 连接成功后,运行以下命令修改 MySQL 配置: ``` ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password'; FLUSH PRIVILEGES; ``` 请将 `your_new_password` 替换为你想要设置的新密码。 9. 退出 MySQL 终端: ``` exit ``` 现在,你已经成功安装 MySQL 8.0 并解决了 "Public Key Retrieval is not allowed" 报错问题。 请记住,在步骤 7 和步骤 8 中,你可以根据自己的需求修改 MySQL 用户和密码。确保在生产环境中使用强密码,并采取其他安全措施来保护你的数据库
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值