本地主机远程连接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