com.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not allowed
时间: 2023-08-16 10:14:32 浏览: 51
这个错误是由于MySQL连接配置中的公钥检索设置引起的。默认情况下,MySQL 8.0版本之后的驱动程序不允许在安全连接上进行公钥检索。这是为了增强安全性而做出的更改。
要解决此问题,您可以尝试以下解决方案之一:
1. 在连接URL中添加`allowPublicKeyRetrieval=true`参数,示例如下:
```java
String url = "jdbc:mysql://localhost:3306/database?allowPublicKeyRetrieval=true";
Connection conn = DriverManager.getConnection(url, username, password);
```
2. 如果您使用的是MySQL Connector/J驱动程序,请确保您使用的是5.1.47版本之后的驱动程序。这些版本对于公钥检索问题进行了修复。
3. 如果您无法更改连接URL或驱动程序版本,可以尝试在MySQL服务器上更改`my.cnf`文件,启用公钥检索。在`[mysqld]`部分添加以下行:
```bash
[mysqld]
...
allowPublicKeyRetrieval=true
```
然后重启MySQL服务器。
通过以上方法之一,您应该能够解决"Public Key Retrieval is not allowed"错误。如果问题仍然存在,请检查您的数据库配置和访问权限是否正确。
相关问题
com.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not allowed.
com.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not allowed 是一个MySQL连接异常,表示无法进行公钥检索。这个异常通常发生在使用MySQL连接时,当MySQL服务器配置不允许进行公钥检索时会抛出该异常。
公钥检索是一种安全机制,用于验证与MySQL服务器的连接。当MySQL服务器配置为不允许公钥检索时,客户端无法获取服务器的公钥,从而导致连接失败。
要解决这个问题,可以尝试以下几种方法:
1. 检查MySQL服务器的配置:确保MySQL服务器允许进行公钥检索。可以通过修改MySQL服务器的配置文件(如my.cnf)来启用公钥检索。
2. 更新MySQL驱动程序:如果您正在使用的是旧版本的MySQL驱动程序,尝试升级到最新版本,以确保与MySQL服务器的兼容性。
3. 使用用户名和密码进行连接:尝试使用用户名和密码进行连接,而不是使用公钥验证。可以在连接字符串中指定用户名和密码来进行连接。
mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not allowed
mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not allowed 是一个MySQL连接异常。这个异常表示无法进行公钥检索。为了解决这个问题,可以在MySQL的连接URL中增加参数allowPublicKeyRetrieval=true。例如,jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true。这样设置后,就能够允许公钥检索,解决了异常问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Caused by: com.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not](https://blog.csdn.net/weixin_44299027/article/details/131766486)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [com.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is no](https://blog.csdn.net/a13662080711/article/details/124837085)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)