zoukankan      html  css  js  c++  java
  • Connection timed out: connect; Communications link failure

    今天过来启动自己的项目出现如下的问题:

    Communications link failure

    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

    百度了一下,原因如下:

    使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误:

    Communications link failure,The last packet successfully received from the server was *** millisecond ago.The last packet successfully sent to the server was ***  millisecond ago。

    测试去连接数据库,果然报错了

    其中错误还会提示你修改wait_timeout或是使用Connector/J的autoReconnect属性避免该错误。

    后来查了一些资料,才发现遇到这个问题的人还真不少,大部分都是使用连接池方式时才会出现这个问题,短连接应该很难出现这个问题。这个问题的原因:

    MySQL服务器默认的“wait_timeout”是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。

    解决办法:

    修改MySQL的参数,wait_timeout最大为31536000即1年,在my.cnf中加入:

    [mysqld]

    wait_timeout=31536000

    interactive_timeout=31536000

    重启生效,需要同时修改这两个参数。

    但是如何找到my.cnf文件呢?又找了半天

  • 相关阅读:
    符号表
    经典算法-堆排序
    AngularJs基础
    Echars详解
    经典算法-快速排序
    经典算法-递归
    异常分类,异常抛出位置
    js的数据类型具体分析
    函数
    数据
  • 原文地址:https://www.cnblogs.com/bystudy/p/6655146.html
Copyright © 2011-2022 走看看