Q:同一个session中,wait_timeout 和 interacitve_timeout是否都会生效。 A:只有wait_timeout 会真正起到超时限制的作用
mysql> set session interactive_timeout=10; Query OK, 0 rows affected (0.00 sec) mysql> set session wait_timeout=20; Query OK, 0 rows affected (0.00 sec) mysql> show full processlist; +----+-------------+-----------------+------+---------+--------+-----------------------------------------------------------------------------+-----------------------+-----------+---------------+-----------+ | Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined | Rows_read | +----+-------------+-----------------+------+---------+--------+-----------------------------------------------------------------------------+-----------------------+-----------+---------------+-----------+ | 1 | system user | | NULL | Connect | 103749 | Slave has read all relay log; waiting for the slave I/O thread to update it | NULL | 0 | 0 | 1 | | 2 | system user | | NULL | Connect | 103750 | Connecting to master | NULL | 0 | 0 | 1 | | 3 | root | localhost | NULL | Query | 0 | NULL | show full processlist | 0 | 0 | 11 | | 10 | root | localhost:58946 | NULL | Sleep | 20 | | NULL | 0 | 0 | 11 | +----+-------------+-----------------+------+---------+--------+-----------------------------------------------------------------------------+-----------------------+-----------+---------------+-----------+ 4 rows in set (0.00 sec) mysql> show full processlist; +----+-------------+-----------+------+---------+--------+-----------------------------------------------------------------------------+-----------------------+-----------+---------------+-----------+ | Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined | Rows_read | +----+-------------+-----------+------+---------+--------+-----------------------------------------------------------------------------+-----------------------+-----------+---------------+-----------+ | 1 | system user | | NULL | Connect | 103749 | Slave has read all relay log; waiting for the slave I/O thread to update it | NULL | 0 | 0 | 1 | | 2 | system user | | NULL | Connect | 103750 | Connecting to master | NULL | 0 | 0 | 1 | | 3 | root | localhost | NULL | Query | 0 | NULL | show full processlist | 0 | 0 | 11 | +----+-------------+-----------+------+---------+--------+-----------------------------------------------------------------------------+-----------------------+-----------+---------------+-----------+ 3 rows in set (0.00 sec)Q:global timeout和session timeout是否都会��为超时判断依据? A:只有session级别 timeout 会起作用。即一个session开始后,无论如何修改global级别的timeout都不会影响该session
测试1:
mysql> set session interactive_timeout = 10; Query OK, 0 rows affected (0.00 sec) mysql> set session wait_timeout = 10; Query OK, 0 rows affected (0.00 sec) mysql> show session variables like '%timeout%'; +----------------------------+----------+ | Variable_name | Value | +----------------------------+----------+ | interactive_timeout | 10 | | wait_timeout | 10 | +----------------------------+----------+ 10 rows in set (0.00 sec) mysql> show global variables like '%timeout%'; +----------------------------+----------+ | Variable_name | Value | +----------------------------+----------+ | interactive_timeout | 20 | | wait_timeout | 20 | +----------------------------+----------+ 10 rows in set (0.00 sec) mysql> show full processlist; +----+-------------+-----------------+------+---------+--------+-----------------------------------------------------------------------------+-----------------------+-----------+---------------+-----------+ | Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined | Rows_read | +----+-------------+-----------------+------+---------+--------+-----------------------------------------------------------------------------+-----------------------+-----------+---------------+-----------+ | 3 | root | localhost | NULL | Query | 0 | NULL | show full processlist | 0 | 0 | 11 | | 17 | root | localhost:60585 | NULL | Sleep | 10 | | NULL | 10 | 10 | 11 | +----+-------------+-----------------+------+---------+--------+-----------------------------------------------------------------------------+-----------------------+-----------+---------------+-----------+ 2 rows in set (0.00 sec) mysql> show full processlist; +----+-------------+-----------+------+---------+--------+-----------------------------------------------------------------------------+-----------------------+-----------+---------------+-----------+ | Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined | Rows_read | +----+-------------+-----------+------+---------+--------+-----------------------------------------------------------------------------+-----------------------+-----------+---------------+-----------+ | 3 | root | localhost | NULL | Query | 0 | NULL | show full processlist | 0 | 0 | 11 | +----+-------------+-----------+------+---------+--------+-----------------------------------------------------------------------------+-----------------------+-----------+---------------+-----------+ 1 rows in set (0.00 sec)