mysql的wait_timeout和interactive_timeout

###wait_timeout interactive_timeout####

wait_timeout :对于非交互连接,mysql在关闭它之前的等待时间
              这个值的初始化根据连接客户端的连接方式不同:有两种方式:全局的wait_timeout或者是全局的interactive_timeout

interactive_timeout:对于交互连接,mysql在关闭它之前的等待时间

测试:
root:3406:(none)>show variables like '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 21       |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| thread_pool_idle_timeout    | 60       |
| wait_timeout                | 21       |
+-----------------------------+----------+
14 rows in set (0.00 sec)

root:3406:(none)>show global variables like '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 21       |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| thread_pool_idle_timeout    | 60       |
| wait_timeout                | 14       |
+-----------------------------+----------+
14 rows in set (0.00 sec)

root:3406:(none)>show global variables like '%timeout%';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    4
Current database: *** NONE ***

+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 21       |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| thread_pool_idle_timeout    | 60       |
| wait_timeout                | 14       |
+-----------------------------+----------+
14 rows in set (0.00 sec)

上面是测试交互输入的方式,
wait_timeout =14
interactive_timeout=21
可以看到session级别的wait_timeout的初始化使用了interactive_timeout
当超过了21s后,再执行命令连接已经被干掉了


综上:
针对client其实真正生效的是session级别的wait_timeout,空闲连接(交互和非交互),
超过其session级别的wait_timeout时间就会被回收掉:
伪代码:
if (client_connection is interactive) then
  session  wait_timeout= global interactive_timeout
else if(client_connection is noninteractive ) then
   session  wait_timeout= global wait_timeout
end if

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20625855/viewspace-1717890/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/20625855/viewspace-1717890/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值