Public Key Retrieval is not allowed
当你在连接 MySQL 数据库时遇到 Public Key Retrieval is not allowed 错误,这通常是由于 MySQL 8.0 默认使用的 caching_sha2_password 身份验证机制导致的。以下是解决此问题的方法。
示例
jdbc:mysql://localhost:3306/your_database?allowPublicKeyRetrieval=true
1. 修改连接字符串
在连接字符串中添加 allowPublicKeyRetrieval=true 参数,以允许公钥检索。
示例:
jdbc:mysql://localhost:3306/your_database?allowPublicKeyRetrieval=true
2. 修改用户身份验证方式
将用户的身份验证方式修改为 mysql_native_password。
示例:
ALTER USER ‘root‘@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘your_password’;
3. 检查 SSL/TLS 设置
确保你的客户端驱动程序支持并正确配置了 SSL/TLS 选项。如果你的 MySQL 服务器已配置为要求 SSL/TLS 连接,请提供正确的 SSL 证书和密钥文件。
通过以上方法,你可以解决 Public Key Retrieval is not allowed 错误,成功连接到 MySQL 数据库。
文档更新时间: 2025-08-01 21:16 作者:admin