java - 计算机重新启动后 Spring 无法连接到 mysql 数据库我该如何诊断问题所在

标签 java mysql spring-boot

我正在使用 spring 连接到同一台计算机上的 mysql 数据库,并从 api 提取数据并存储它。它昨天正在工作,我决定让它继续运行,看看是否遇到任何问题。据我所知,它工作得很好,但我忘记插入笔记本电脑,它就死机了。重新启动计算机后,我可以通过命令行连接到数据库,但我的应用程序无法使用相同的用户 ID 和密码进行连接。

我尝试按照 spring.io 指南再次连接到 mysql,并且尝试修改我的应用程序属性以使用 127.0.0.1

我还验证了凭据在命令行上有效并允许我连接到我的 mysql 数据库

应用程序属性

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/POE?autoReconnect=true&useSSL=false
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.profiles.default=production
spring.profiles.active=production

pom.xml - mysql 连接器 ...

<!-- Use MySQL Connector-J -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.3</version>
</dependency>

...

我可以展示更多实际代码,但它主要是我自己的实体从 spring.io 指南中摘录的。但如果我没有建立连接,我认为这不是问题

它运行良好,只是记录我对数据库所做的所有写入,但现在我收到此错误

2019-07-09 14:57:45.839 ERROR 2654 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

最佳答案

增加数据库的超时时间。如果MySql闲置时间超过8小时,则默认关闭。

关于java - 计算机重新启动后 Spring 无法连接到 mysql 数据库我该如何诊断问题所在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56959292/

相关文章:

spring-boot - 如何在带有嵌入式 tomcat 的 Spring Boot 应用程序中运行 hawt.io

java - 我的 Richfaces 4.0 项目无法与 ui 一起使用 :composition tag

java - 每次我从 HIbernate 检索一个实体然后丢弃时,Hibernate 是否会挂起任何资源

java - org.hibernate.HibernateException : Unable to instantiate default tuplizer

mysql - Woocommerce 批量更改订单状态

mysql - 如何使用 JOIN 和 WHERE 语句过滤记录?

java - spring boot xa事务数据源和jms

java - 使用 GSON 将 Java 接口(interface)转换为 JSON 字符串,而不将序列化封装在 JSON 对象中?

MYSQL - 如果选择日期中没有行,如何设置零

javascript - 无法以 Angular 7 导出 excel (xlsm) - 使用 spring boot 后端