zoukankan      html  css  js  c++  java
  • 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,让连接一直或者,就不会再有超时的问题了。
     
     
     
     
     
  • 相关阅读:
    ExecutorService 和 NSOperationQueue
    Android 中的AsyncTask
    正则表达式里"-"中划线的使用注意
    Android studio 程序升级和sdk manager 升级方法
    推荐一篇java抽象类和接口区别的文章
    Android measure和layout的一点理解
    Android 屏幕旋转
    Android 中的openurl
    UML 序列图一点理解
    Android Studio中的Module,Facet
  • 原文地址:https://www.cnblogs.com/liuweiqiang/p/mysql2.html
Copyright © 2011-2022 走看看