今天一同事反馈用SQuirreL SQL Client工具连接mysql,查询表数据时,本来可以正常查询,但隔一两分钟,再重新查询,结果就会报错:
Error: com.mysql.jdbc.CommunicationsException: 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:1956)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2368)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3178)
at com.mysql.jdbc.Statement.execute(Statement.java:682)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.processQuery(SQLExecuterTask.java:336)
at net.sourceforge.squirrel_sql.client.session.SQLExecuterTask.run(SQLExecuterTask.java:210)
at net.sourceforge.squirrel_sql.fw.util.TaskExecuter.run(TaskExecuter.java:82)
at java.lang.Thread.run(Thread.java:722)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago., SQL State: 08S01, Error Code: 0
其中发现,SHOW VARIABLES LIKE '%timeout%';和SHOW GLOBAL VARIABLES LIKE '%timeout%';查询结果竟然不一样。后来了解到要在配置文件里同时设置interactive_timeout和wait_timeout,会话变量才会生效。