报错信息:
java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not all
在url的后边加上 allowPublicKeyRetrieval=true
即可
文档地址:(MySQL Connection String for C# .NET Core Programs - MySqlConnector)
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 theServerRSAPublicKeyFile
connection string setting, or setAllowPublicKeyRetrieval=True
to allow the client to automatically request the public key from the server. Note thatAllowPublicKeyRetrieval=True
could allow a malicious proxy to perform a MITM attack to get the plaintext password, so it isFalse
by default and must be explicitly enabled.
翻译:
如果用户帐户使用sha256_password身份验证,则在传输过程中必须保护密码;TLS是首选的机制,但如果它不可用,则将使用RSA公钥加密。要指定服务器的RSA公钥,请使用ServerRSAPublicKeyFile连接字符串设置,或将AllowPublicKeyRetrieval=True设置为允许客户端自动向服务器请求公钥。请注意,AllowPublicKeyRetrieval=True可能允许恶意代理执行MITM攻击以获取明文密码,因此默认情况下它为False,必须显式启用。