国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL中interactive_timeout和wait_timeout的區別

2024-07-24 12:53:29
字體:
來源:轉載
供稿:網友

在用mysql客戶端對數據庫進行操作時,打開終端窗口,如果一段時間沒有操作,再次操作時,常常會報如下錯誤:

ERROR 2013 (HY000): Lost connection to MySQL server during queryERROR 2006 (HY000): MySQL server has gone awayNo connection. Trying to reconnect...

這個報錯信息就意味著當前的連接已經斷開,需要重新建立連接。

那么,連接的時長是如何確認的?

其實,這個與interactive_timeout和wait_timeout的設置有關。

首先,看看官方文檔對于這兩個參數的定義

interactive_timeout

默認是28800,單位秒,即8個小時

The number of seconds the server waits for activity on an interactive connection before closing it. An interactive client is defined as a client that uses the CLIENT_INTERACTIVE option to mysql_real_connect(). See also wait_timeout.

wait_timeout

默認同樣是28800s

The number of seconds the server waits for activity on a noninteractive connection before closing it.

On thread startup, the session wait_timeout value is initialized from the global wait_timeout value or from the global interactive_timeout value, depending on the type of client (as defined by the CLIENT_INTERACTIVE connect option to mysql_real_connect()). See also interactive_timeout.

根據上述定義,兩者的區別顯而易見

1> interactive_timeout針對交互式連接,wait_timeout針對非交互式連接。所謂的交互式連接,即在mysql_real_connect()函數中使用了CLIENT_INTERACTIVE選項。

說得直白一點,通過mysql客戶端連接數據庫是交互式連接,通過jdbc連接數據庫是非交互式連接。

2> 在連接啟動的時候,根據連接的類型,來確認會話變量wait_timeout的值是繼承于全局變量wait_timeout,還是interactive_timeout。

下面來測試一下,確認如下問題

1. 控制連接最大空閑時長的是哪個參數。

2. 會話變量wait_timeout的繼承問題

Q1:控制連接最大空閑時長的是哪個參數

A1:wait_timeout

驗證

只修改wait_timeout參數

mysql> select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');+---------------------+----------------+| variable_name | variable_value |+---------------------+----------------+| INTERACTIVE_TIMEOUT | 28800 || WAIT_TIMEOUT | 28800 |+---------------------+----------------+2 rows in set (0.03 sec)mysql> set session WAIT_TIMEOUT=10;Query OK, 0 rows affected (0.00 sec)-------等待10s后再執行mysql> select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');ERROR 2013 (HY000): Lost connection to MySQL server during query

可以看到,等待10s后再執行操作,連接已經斷開。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 白河县| 定结县| 张家口市| 临澧县| 安仁县| 宜兰市| 汕尾市| 平定县| 沅陵县| 广州市| 兴义市| 吴忠市| 柘荣县| 三都| 施甸县| 新晃| 边坝县| 嘉鱼县| 平阳县| 鹤山市| 甘孜| 平定县| 独山县| 开化县| 陵川县| 青阳县| 德江县| 新乐市| 崇礼县| 盱眙县| 镇雄县| 黑水县| 江达县| 武穴市| 东海县| 美姑县| 澄城县| 曲麻莱县| 师宗县| 莫力| 新晃|