java - Spring 启动: MySQLNonTransientConnectionException: Could not create connection

标签 java mysql spring spring-boot

我正在尝试将我的 Spring Boot 应用程序与 MySQL 服务器连接。

我已正确遵循文档,但仍然遇到一些相关问题 每次都会抛出以下异常

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

最佳答案

为了解决这个错误,我必须使用 MySql Workbench 使用存储在 application.properties 文件中的用户名和密码登录 MySql。执行此操作后,该错误不再出现。仅当尝试在重新启动 MySql 服务器后运行我的 spring boot 项目时,才会发生这种情况。

更新:将“&allowPublicKeyRetrieval=true”添加到 application.properties 文件中的 spring.datasource.url 解决了问题。在我注意到日志中的另一个错误后我发现了这一点:“不允许 MySQL 公钥检索”

spring.datasource.url=jdbc:mysql://localhost:3306/db_example?autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true

关于java - Spring 启动: MySQLNonTransientConnectionException: Could not create connection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51243403/

相关文章:

Java - 自定义整数除法函数

java - 连接到本地 MS SQL Server

mysql - 字符串搜索返回 0 行

python - 如何在 Beautifulsoup 中分解 HTML 元素以将它们插入到 MySQL 数据库表中?

java - 如何验证 java 中的文本字段

java - 如何在 JPA 中创建假谓词

mysql - 在没有设置任何数据库的情况下,如何将 CSV 文件转换为基于 Web 的 SQL 数据库表?

java - POST 到 Spring MVC Controller 结果为 "HttpMessageNotReadableException: Could not read JSON: No suitable constructor found"

java - 上下文初始化失败——BeanCreationNotAllowedException

java - Spring - 使用 CriteriaQuery (规范)的 OrderBy 关系属性会忽略没有关系的行