com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Public Key Retrieval is not allowed

时间: 2023-11-12 22:57:23 浏览: 55
这个异常通常是由于 MySQL 8.0 版本以上的 JDBC 驱动程序默认启用了 SSL/TLS 加密连接,但是在某些情况下,MySQL 服务器可能无法提供必要的证书或者 SSL/TLS 加密连接被禁用。为了解决这个问题,可以尝试以下两种方法: 1. 在 JDBC URL 中添加参数 `&allowPublicKeyRetrieval=true`,例如: ``` jdbc:mysql://localhost:3306/mydatabase?useSSL=false&allowPublicKeyRetrieval=true ``` 2. 在 MySQL 服务器上启用 SSL/TLS 加密连接,具体方法可以参考 MySQL 官方文档。
相关问题

Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Public Key Retrieval is not allowed

这个错误通常是由于 MySQL 8.0 版本引入了更严格的安全策略所致,其中默认情况下禁用了使用旧的加密方法。这可能会导致某些 JDBC 驱动程序无法建立安全连接,因此您需要更新您的 JDBC 驱动程序并使用新的安全连接选项。 您可以从 MySQL 官方网站下载 MySQL Connector/J 驱动程序的最新版本,并将其替换为旧版本的驱动程序。如果您使用的是 Maven,可以更新您的 pom.xml 文件以使用最新版本的 Connector/J。 另外,您还可以在 JDBC 连接字符串中添加 `allowPublicKeyRetrieval=true` 选项来启用允许公钥检索的连接。例如: ``` jdbc:mysql://localhost:3306/mydatabase?allowPublicKeyRetrieval=true ``` 这将允许使用旧的加密方法建立安全连接,但请注意这可能会降低安全性。 希望这些方法能帮助您解决问题。

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 ]

相关推荐

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

pre_o_1csdn63m9a1bs0e1rr51niuu33e.a

pre_o_1csdn63m9a1bs0e1rr51niuu33e.a
recommend-type

matlab建立计算力学课程的笔记和文件.zip

matlab建立计算力学课程的笔记和文件.zip
recommend-type

FT-Prog-v3.12.38.643-FTD USB 工作模式设定及eprom读写

FT_Prog_v3.12.38.643--FTD USB 工作模式设定及eprom读写
recommend-type

matlab基于RRT和人工势场法混合算法的路径规划.zip

matlab基于RRT和人工势场法混合算法的路径规划.zip
recommend-type

matlab基于matlab的两步定位软件定义接收机的开源GNSS直接位置估计插件模块.zip

matlab基于matlab的两步定位软件定义接收机的开源GNSS直接位置估计插件模块.zip
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的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。