美文网首页MySQL
mysql连接池超时问题「随笔」

mysql连接池超时问题「随笔」

作者: Helloword_Cc | 来源:发表于2019-08-28 09:51 被阅读9次

    最近项目上服务器出现报错,导致数据库访问异常:

    The last packet successfully received from the server was 575,123 milliseconds ago. The last packet sent successfully to the server was 575,130 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.

    原因:mysql设置了连接的超时时间,在JDBC的xml配置也设置了超时时间,而xml配置的时间比mysql的长。所以当连接被mysql断开后,JDBC还不知道,以为是一条正常的连接,又继续使用,就导致问题。

    「mysql直接在mysql执行语句,!!只是临时修改,重启后又会恢复」

    set global wait_timeout=2000; //设置连接有效时间,单位:秒
    

    xml 配置连接有效时间:

        <!-- 1800秒,也就是30分钟 -->
        <property name="removeAbandonedTimeout" value="1800" />
    

    小总结:mysql设置超时时间应比连接池时间长,不然会出现mqsql已经将连接断开,而连接池不知道,将失效的连接继续使用。

    相关文章

      网友评论

        本文标题:mysql连接池超时问题「随笔」

        本文链接:https://www.haomeiwen.com/subject/oiauectx.html