.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not allowed

时间: 2023-11-28 16:45:33 浏览: 54
这个错误通常是由于MySQL 8.0版本以上的驱动程序默认启用了SSL,而且需要使用公钥加密来检索数据。如果MySQL服务器未正确配置,则会出现此错误。解决此问题的方法是在JDBC URL中添加一个参数,以允许使用旧的不安全的公钥检索方法。具体方法如下: ```java String url = "jdbc:mysql://localhost:3306/mydatabase?useSSL=false&allowPublicKeyRetrieval=true"; ``` 在这个URL中,`useSSL=false`表示禁用SSL,`allowPublicKeyRetrieval=true`表示允许使用旧的不安全的公钥检索方法。如果你使用的是Spring Boot,可以在`application.properties`文件中添加以下配置: ``` spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase?useSSL=false&allowPublicKeyRetrieval=true ``` 这将覆盖默认的JDBC URL并解决该问题。
相关问题

com.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not allowed

com.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not allowed是一个数据库连接的错误,它意味着无法连接到MySQL数据库。解决这个问题的方法是在连接URL中添加一个参数allowPublicKeyRetrieval=true。具体的解决方案如下: 1. 在你的Java Spring Boot项目中,找到连接数据库的配置文件。 2. 在配置文件中的spring.datasource.url参数后添加allowPublicKeyRetrieval=true。例如: jdbc:mysql://localhost:3306/mydatabase?allowPublicKeyRetrieval=true 注意:要根据你的具体数据库配置进行相应的修改。 这样做的原因是,当使用sha256_password认证方式时,密码在传输过程中必须使用TLS协议进行保护。但是,如果服务器的RSA公钥不可用,可以通过设置allowPublicKeyRetrieval=true参数来允许从服务器获取公钥。需要注意的是,开启此选项可能会导致中间人攻击获取到明文密码,因此默认情况下是关闭的,需要显式地开启。 希望以上解决方案能帮助你解决com.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not allowed的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [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_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [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_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [解决Cause com.mysql.jdbc.exceptions.jdbc4.CommunicationsException](https://download.csdn.net/download/lj_70596/39157301)[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_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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. 使用用户名和密码进行连接:尝试使用用户名和密码进行连接,而不是使用公钥验证。可以在连接字符串中指定用户名和密码来进行连接。

相关推荐

Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed ### The error may exist in mysql/user/mappers/usermapper.xml ### The error may involve mysql.user.mappers.usermapper.selectAll ### The error occurred while executing a query ### Cause: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) at com.sun.proxy.$Proxy4.selectAll(Unknown Source) at org.example.main2.main(main2.java:25) Caused by: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:829) at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:449) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:242) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) at java.sql.DriverManager.getConnection(Driv

java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228) at comm.login$GetConnection.GetConnection(login.java:171) at JZS.comm.util.CheckUsers.<init>(CheckUsers.java:13) at comm.login.actionPerformed(login.java:107) at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967) at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308) at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405) at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262) at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279) at java.desktop/java.awt.Component.processMouseEvent(Component.java:6636) at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342) at java.desktop/java.awt.Component.processEvent(Component.java:6401) at java.desktop/java.awt.Container.processEvent(Container.java:2263) at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844) at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java

最新推荐

recommend-type

基于Python的蓝桥杯竞赛平台的设计与实现

【作品名称】:基于Python的蓝桥杯竞赛平台的设计与实现 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【项目介绍】:基于Python的蓝桥杯竞赛平台的设计与实现
recommend-type

python实现基于深度学习TensorFlow框架的花朵识别项目源码.zip

python实现基于深度学习TensorFlow框架的花朵识别项目源码.zip
recommend-type

3-9.py

3-9
recommend-type

郊狼优化算法COA MATLAB源码, 应用案例为函数极值求解以及优化svm进行分类,代码注释详细,可结合自身需求进行应用

郊狼优化算法COA MATLAB源码, 应用案例为函数极值求解以及优化svm进行分类,代码注释详细,可结合自身需求进行应用
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

2. 通过python绘制y=e-xsin(2πx)图像

可以使用matplotlib库来绘制这个函数的图像。以下是一段示例代码: ```python import numpy as np import matplotlib.pyplot as plt def func(x): return np.exp(-x) * np.sin(2 * np.pi * x) x = np.linspace(0, 5, 500) y = func(x) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('y = e^{-x} sin(2πx)') plt.show() ``` 运行这段
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依