###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
mysql的wait_timeout和interactive_timeout
原文:http://blog.itpub.net/20625855/viewspace-1717890/