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

來源:互聯網
上載者:User

標籤:

關於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是不生效的。

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.