刚开始写java,立即遇上一堆名词:jetty,maven,spring等等。这不,一个问题卡住了我半天:
project里使用了c3p0连接池(链接),用于管理jdbc与mysql的连接。问题是每次select数据都会返回同样的错误:
Communications link failure,The last packet successfully received from the server was 9,981 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago
修改办法如下:
1.修改配置
在 /etc/my.cnf 文件里,增加 [mysqld] wait_timeout=10 ,重启mysql:# /etc/init.d/mysql restart
2.直接用sql命令行修改 mysql> set global wait_timeout=604800; 除了wait_timeout,还有一个'interactive_timeout' 同样可以执行SHOW GLOBAL VARIABLES LIKE 'interactive_timeout'来查询 执行set global interactive_timeout=604800;来设置
初步怀疑是jdbc与mysql建立的连接持续时间过段,因此通过增加wait_timeout即可以修正问题。