zoukankan      html  css  js  c++  java
  • Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决

    springboot + mybatis多数据库 + druid连接池配置成功。正常运行后,访问第一个数据库后访问第二个数据库,再去访问第一个数据库 会报错:

    ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    The last packet successfully received from the server was 8,451 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
    ### The error may exist in com/bwton/dist/dao/sys/DictDao.xml
    ### The error may involve defaultParameterMap
    ### The error occurred while setting parameters
    ### SQL: select id,code,value,caption,status, create_user,create_time,update_user,update_time from dictionary where code = ? and value <> "!" and status = "1" order by value
    ### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    The last packet successfully received from the server was 8,451 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
    ; SQL []; Communications link failure

    The last packet successfully received from the server was 8,451 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    The last packet successfully received from the server was 8,451 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
    at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98)

    网上查了下,原因是
    MySQL服务器默认的“wait_timeout”是28800秒即8小时(查看mysql实际wait_timeout可以用sql命令:show global variables like ‘wait_timeout’?,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。

    解决方法:

    • 1、修改my.cnf:
      [mysqld]
      wait_timeout=31536000
      interactive_timeout=31536000
      将过期时间修改为1年。
    • 2、在连接URL上添加参数:&autoReconnect=true&failOverReadOnly=false

    我的解决采用的是第二种方法,在URL后面加上&autoReconnect=true&failOverReadOnly=false

    网上搜索参考自:

    https://blog.csdn.net/a704397849/article/details/93797529

    在此也感谢开发老表的协助。

  • 相关阅读:
    【解决】Word中插入图片后变模糊(失真)
    【解决】Windows文件夹没有边框
    【解决】电脑字体突然显示不正常
    NLP与深度学习(六)BERT模型的使用
    NLP与深度学习(五)BERT预训练模型
    NLP与深度学习(四)Transformer模型
    NLP与深度学习(三)Seq2Seq模型与Attention机制
    用ByteArrayOutputStream解决IO流乱码问题
    在vue3中使用vue-property-decorator报错
    python之批量打印网页为pdf文件(二)
  • 原文地址:https://www.cnblogs.com/yanghj010/p/14663727.html
Copyright © 2011-2022 走看看