Mysql默认状态下 空闲8小时就会自动断开,这是我第一次去链接数据库就会出现这样的错误The last packet successfully received from the server was 57,350,142 milliseconds ago.  The last packet sent successfully to the server was 57,350,142 milliseconds ago. 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.请教解决方案。顺便附上我的环境
tomcat5.5
Mysql5.1.50
Connector/J: mysql-connector-java-5.1.8

解决方案 »

  1.   

    增大这个wait_timeout'系统变量就行了。
      

  2.   

    临时增大的方法,直接执行SQL命令 
    set wait_timeout=  57,350,142;永久性则需要在你的INI文件中修改。
    另外就是什么语句需要执行这么长时候? 是数据量大?还是什么其它原因,毕竟一个语句需要 57,350,142这么长时间 15个小时也的确是有些长了。
      

  3.   

    但是即使wait_timeout再大, 空闲时间超过这个值,总会出现这个问题啊
      

  4.   

    那就需要在你的程序中处理了。 一般现在流行的设计方法是数据库用完后就关闭,再次使用的时间再连接。这样也减少对数据库SESSION资源的占用。
      

  5.   

    可能我没有描述清楚现在的情况是,比如我前一天下班之后再也没有链接过数据库,第二天早上第一次去connect数据库就会出现这个错误,但是第二次再去connect就没有问题了。难不成每次出这个错误,我都要执行2次connect?
      

  6.   

    改用proxool等连接池,不要用自带的dbcp