转载自:http://www.cnblogs.com/azhqiang/p/5454000.html
关于wait_timeout
有一次去online set wait_timeout 的时候发现改了不生效,如下:
mysql> show variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 100 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> set global wait_timeout=28800;
退出后重新登录mysql
mysql> show variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 100 |
+---------------+-------+
1 row in set (0.00 sec)
网上搜索了一下:
说法1:
interactive_timeout和wait_timeout的默认值都是28800(8小时)当这两个参数同时出现在里时,会以interactive_timeout的值为准。也就是说不管wait_timeout的值是多少,用show variables like '%timeout%';查看时显示的两个值都是一样的,并且都是interactive_timeout的值。
说法2:如果查询时使用的是show variables的话,会发现设置好像并没有生效,这是因为单纯使用show variables的话就等同于使用的是show session variables,查询的是会话变量,只有使用show global variables,查询的才是全局变量。网络上很多人都抱怨说他们set global之后使用show variables查询没有发现改变,原因就在于混淆了会话变量和全局变量,如果仅仅想修改会话变量的话,可以使用类似set wait_timeout=10;或者set session wait_timeout=10;这样的语法。
验证一下说法1:修改interactive_timeout 是否可以达到修改wait_timeout的效果
mysql> show variables like '%timeout'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | connect_timeout | 10 | | delayed_insert_timeout | 300 | | interactive_timeout | 200 | | net_read_timeout | 30 | | net_write_timeout | 60 | | slave_net_timeout | 3600 | | table_lock_wait_timeout | 50 | | wait_timeout | 200 | +-------------------------+-------+ 8 rows in set (0.00 sec)
mysql> set global interactive_timeout=100; Query OK, 0 rows affected (0.00 sec)
mysql>show variables like '%timeout'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | connect_timeout | 10 | | delayed_insert_timeout | 300 | | interactive_timeout | 200 | | net_read_timeout | 30 | | net_write_timeout | 60 | | slave_net_timeout | 3600 | | table_lock_wait_timeout | 50 | | wait_timeout | 200 | +-------------------------+-------+ 8 rows in set (0.00 sec)
mysql> show global variables like '%timeout'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | connect_timeout | 10 | | delayed_insert_timeout | 300 | | interactive_timeout | 100 | | net_read_timeout | 30 | | net_write_timeout | 60 | | slave_net_timeout | 3600 | | table_lock_wait_timeout | 50 | | wait_timeout | 200 | +-------------------------+-------+ 8 rows in set (0.00 sec)
mysql> exit 退出后重新登录mysql
mysql> show variables like '%timeout'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | connect_timeout | 10 | | delayed_insert_timeout | 300 | | interactive_timeout | 100 | | net_read_timeout | 30 | | net_write_timeout | 60 | | slave_net_timeout | 3600 | | table_lock_wait_timeout | 50 | | wait_timeout | 100 | +-------------------------+-------+ 8 rows in set (0.00 sec)
以上可以看到,如果修改interactive_timeout的话wait_timeout也会跟着变,而只修改wait_timeout是不生效的。