The last packet successfully received from the server was52536 seconds ago.The last packet sent successfully to the server was 52536 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
问:怎样才能解决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