Home > Database > Mysql Tutorial > mysql 8小时空闲后连接超时的问题_MySQL

mysql 8小时空闲后连接超时的问题_MySQL

WBOY
Release: 2016-06-01 13:55:53
Original
1063 people have browsed it

  问:怎样才能解决mysql 8小时空闲后连接超时的问题?

  答:当应用程序和数据库建立连接时,如果超过了8个小时,应用程序句不会去访问数据库,数据库就会出现断掉连接的现象 。这时再次访问就会抛出异常,异常如下:

Communications link failure due to
underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:
java.io.EOFException
  at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1913)
  at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
  at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
...

  一般的解决方法大多是在数据库连接字符串中增加“autoReconnect=true ”选项。但是这只对mysql4以前的版本有效。在最新的mysql中是无效的。其实要解决这个问题也有一个简单的方法,就是修改mysql的启动参数。缺省情况下mysql的timeout时间是28800秒,正好是8小时,增加一个0就可以了。

  同理也可以在" my.ini"文件中增加此参数。

mysqld-nt --default-table-type=innodb --interactive_timeout=288000

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