MySQL查詢超時(shí)問(wèn)題的解決
MySQL查詢超時(shí)問(wèn)題是什么原因呢?應(yīng)該如何解決呢?下面就為您詳細(xì)介紹MySQL查詢超時(shí)問(wèn)題的解決方法,希望可以幫助到您。
- mysql>show variables like '%timeout';
打印結(jié)果如下:
- +----------------------------+-------+
- | Variable_name | Value |
- +----------------------------+-------+
- | connect_timeout | 5 |
- | delayed_insert_timeout | 300 |
- | interactive_timeout | 28800 |
- | net_read_timeout | 30 |
- | net_write_timeout | 60 |
- | slave_net_timeout | 3600 |
- | wait_timeout | 28800 |
- +----------------------------+-------+
interactive_timeout 需在mysql_connect()設(shè)置CLIENT_INTERACTIVE選項(xiàng)后起作用,并被賦值為wait_timeout;
mysql>set wait_timeout = 10; 對(duì)當(dāng)前交互鏈接有效;
mysql>set interactive_timeout = 10; 對(duì)后續(xù)起的交互鏈接有效;
該超時(shí)時(shí)間單位是秒,從變量從上次SQL執(zhí)行后算起;當(dāng)前空閑若超過(guò)該時(shí)間,則也會(huì)被強(qiáng)制斷開(kāi)。
interactive_timeout(常用)
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.
譯解:客戶端和服務(wù)器交互的空閑超時(shí)時(shí)間。該系統(tǒng)變量?jī)H當(dāng)客戶端連接服務(wù)器時(shí)設(shè)置了“MYSQL_CLIENT_INTERACTIVE”標(biāo)志才生效,例如:
- //啟用MYSQL_CLIENT_INTERACTIVE模式,連接數(shù)據(jù)庫(kù)服務(wù)器
- $link = mysql_connect($host, $user, $pwd, false, MYSQL_CLIENT_INTERACTIVE);
【編輯推薦】