• Communications link failure


    针对数据库Communications link failure的错误,可以理解为有两种策略解决:
    策略1(推荐):
        数据池配置 <property name="minEvictableIdleTimeMillis" value="28800" />属性,和数据库变量wait_timeout一致。
    策略2:    
        数据池配置
        <!-- testWhileIdle会定时校验numTestsPerEvictionRun个连接,只要发现连接失效,就将其移除再重新创建-->
            <property name= "testWhileIdle" value="true" />
            <!-- 从池中取连接的时候,发现当前连接失效,再创建一个连接供当前查询使用-->
            <property name= "testOnBorrow" value="false" />
            <!-- 连接在return给pool时,是否提前进行validate操作-->
            <property name= "testOnReturn" value="false" />
            <!-- 测试连接是否有效的sql-->
            <property name= "validationQuery" value="select 1" />  
            <!-- 检查连接池中空闲的连接的频率:毫秒-->
            <property name= "timeBetweenEvictionRunsMillis" value="30000" />  
            <!-- 每次检查空闲连接的个数-->
            <property name= "numTestsPerEvictionRun" value="30" />     
          一套属性,定期检查连接,发现无效的则关闭。

    策略3:

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

    [mysqld]

    wait_timeout=31536000(1年)259200(3天:个人推荐)

    interactive_timeout=31536000

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

    !!!需要重启


  • 相关阅读:
    leetcode------Palindrome Number
    leetcode------Minimum Depth of Binary Tree
    leetcode------Binary Tree Level Order Traversal II
    leetcode------Plus One
    leetcode------Plus One
    leetcode------Min Stack
    leetcode------Binary Tree Level Order Traversal
    递归树与非递归树的不同实现【转载,个人感觉写的比较好的一篇,值得去思考】
    leetcode------Compare Version Numbers
    leetcode------Majority Element
  • 原文地址:https://www.cnblogs.com/zhaojinxin/p/7660285.html
Copyright © 2020-2023  润新知