• mysql连接超时


    这几天在跟踪一个项目的时候,老是发现mysql连接报timeout的异常。

    Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 
    The last packet successfully received from the server was 227,004,830
    milliseconds ago.  The last packet sent successfully to the server was
    227,004,830 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自身的一个机制,若该连接在8小时只能没有任何活动,mysql就会断开该连接,但是连接还在连接池里边,再次请求数据库的时候,就会出现如上所述的异常。
     
    初步查找解决方案,是在数据库连接语句里边加上:autoreconnect=true,加上之后,问题依然没有得到解决,只对mysql4之前的版本才有效果。
     
    要增加wait_timeout和interractive_timeout的值,但是增加之后,依然会存在超时的风险,没有从根本上解决问题。
     
    咨询DBA得知,autoreconnect=true这个属性不起作用;需要在配置文件里边加上如下语句:
     
     
    对连接进行test,执行select 1,让连接一直或者,就不会再有超时的问题了。
     
     
     
     
     
  • 相关阅读:
    【POJ 2923】Relocation(状压DP+DP)
    【HDU 2955】Robberies(DP)
    【POJ 2250】Compromise(最长公共子序列LCS)
    【URAL 1917】Titan Ruins: Deadly Accuracy(DP)
    【POJ 1273】Drainage Ditches(网络流)
    HDU2896 病毒侵袭[AC自动机]
    1516. 棋盘上的车[组合数学][状态压缩]
    [HAOI2012] 容易题[母函数]
    [HAOI2012] 高速公路
    [HAOI2012]Road
  • 原文地址:https://www.cnblogs.com/liuweiqiang/p/mysql2.html
Copyright © 2020-2023  润新知