關於mysql的wait_timeout參數 設置不生效的問題


關於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;
Query OK, 0 rows affected (0.00 sec)

mysql>  exit
Bye
 

退出后重新登錄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
Bye

退出后重新登錄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)

mysql>

 

以上可以看到,如果修改interactive_timeout的話wait_timeout也會跟着變,而只修改wait_timeout是不生效的。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM