mysql的waitimeout

首先,我们看下

show GLOBAL VARIABLES like '%timeout%';

默认值为28800s即8小时,我们改为100s

# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 0.0.0.0
wait_timeout=100
interactive_timeout=100

重新查看结果

4033700-8b58c117bc70e44a.png
image

查看对守护进程连接的影响

 public function longT()
    {
        $TicketModel = new TicketModel();
        $this->success('开始建立连接...');
        while (true) {
            sleep(120);
            dump($TicketModel->select('t_id')->fetch());
        }
    }

发现在100s后的连接已被主动断开

4033700-22769213890725a6.png
image

代码中的场景是,在wait_timeout之内无任何操作会自动关闭

官方解释

interactive_timeout 28800

The number of seconds the server waits for activity on an interactive connection before closing it. An interactive client is defined as a client that uses the CLIENT_INTERACTIVE option to mysql_real_connect(). See also wait_timeout.

waitimeout 28800

The number of seconds the server waits for activity on a noninteractive connection before closing it.

On thread startup, the session wait_timeout value is initialized from the global wait_timeout value or from the global interactive_timeout value, depending on the type of client (as defined by the CLIENT_INTERACTIVE connect option to mysql_real_connect()). See also interactive_timeout.

通过MySQL客户端连接db的是交互会话,通过jdbc等程序连接db的是非交互会话。

总结:

如果应用程序长时间的使用一个连接,而有机会长时间不进行任何操作。则会导致连接被关闭。

参考文献:

1.https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html
2.https://cloud.tencent.com/developer/article/1181515

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值