Home > Database > Mysql Tutorial > mysql数据库连接空闲超过8小时自动断开,项目无法连接数据库_MySQL

mysql数据库连接空闲超过8小时自动断开,项目无法连接数据库_MySQL

WBOY
Release: 2016-06-01 13:08:44
Original
1052 people have browsed it

公司的一个项目,放在阿里云上测试
当天都能正常访问,结果睡了一觉就显示无法连接到数据库,纠结了几天 
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state. 

上网查找原因,原来是mysql数据库连接超时,默认是8小时28800秒 

mysql>show global variables like 'wait_timeout';

执行这条语句我们可以看到,显示的结果为28800s=8小时 
我的是linux版的 
更改/etc/my.cnf文件(有些是/etc/mysql/my.cnf)

windows对应的叫my.ini 
在[mysqld]增加wait_timeout=

测试显示问题解决了。

注:解决方案来自网络,感谢他们,希望能帮助其他人

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