Home > Database > Mysql Tutorial > body text

Detailed introduction on how to use Spring Boot to solve Mysql disconnection problem

黄舟
Release: 2017-03-21 13:28:05
Original
1702 people have browsed it

This article mainly introduces how Spring Boot solves the Mysql disconnection problem. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor and take a look.

During the process of connecting Spring Boot JPA to Mysql, you will find a disconnection after 8 hours. The application.properties configuration is as follows (I skip this pit, welcome to join):

spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
Copy after login

Cause analysis:

Mysql by default, if a connection is found If the idle time exceeds 8 hours, the connection will be automatically closed on the database side. (mysql wait_timeout is 8 hours).

Solution:

1. Before Mysql 5 version, you can add autoReconnect=true after the URL, such as:

spring.datasource.url=jdbc:mysql://localhost/test?autoReconnect=true
Copy after login

2 . Add:

spring.datasource.test-on-borrow=false
spring.datasource.test-while-idle=true
spring.datasource.time-between-eviction-runs-millis= 3600000
Copy after login

3 to the application.properties file. Modify the wait_timeout time directly and crudely:

show global variables like 'wait_timeout';
Copy after login

Recommend the second method

The above is the detailed content of Detailed introduction on how to use Spring Boot to solve Mysql disconnection problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!