本篇文章為大家展示了MySQL中怎么設置查詢超時,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
創(chuàng)新互聯(lián)建站是創(chuàng)新、創(chuàng)意、研發(fā)型一體的綜合型網(wǎng)站建設公司,自成立以來公司不斷探索創(chuàng)新,始終堅持為客戶提供滿意周到的服務,在本地打下了良好的口碑,在過去的十余年時間我們累計服務了上千家以及全國政企客戶,如地磅秤等企業(yè)單位,完善的項目管理流程,嚴格把控項目進度與質(zhì)量監(jiān)控加上過硬的技術實力獲得客戶的一致贊賞。為了優(yōu)化OceanBase的query timeout設置方式,特調(diào)研MySQL關于timeout的處理,記錄如下。
[plain]
mysql> show variables like '%time%';
+----------------------------+-------------------+
| Variable_name | Value |
+----------------------------+-------------------+
| connect_timeout | 10 |
| datetime_format | %Y-%m-%d %H:%i:%s |
| delayed_insert_timeout | 300 |
| flush_time | 1800 |
| innodb_lock_wait_timeout | 50 |
| innodb_old_blocks_time | 0 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lc_time_names | en_US |
| lock_wait_timeout | 31536000 |
| long_query_time | 10.000000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| slave_net_timeout | 3600 |
| slow_launch_time | 2 |
| system_time_zone | |
| time_format | %H:%i:%s |
| time_zone | SYSTEM |
| timed_mutexes | OFF |
| timestamp | 1366027807 |
| wait_timeout | 28800 |
+----------------------------+-------------------+
21 rows in set, 1 warning (0.00 sec)
重點解釋其中幾個參數(shù):
connect_timeout:
The number of seconds that the mysqld server waits for a connect packet before respondingwith Bad handshake. The default value is 10 seconds as of MySQL 5.1.23 and 5 seconds before that. Increasing the connect_timeout value might help if clients frequently encounter errors of the form Lost connection to MySQL server at ‘XXX’, system error: errno.
解釋:在獲取鏈接時,等待握手的超時時間,只在登錄時有效,登錄成功這個參數(shù)就不管事了。主要是為了防止網(wǎng)絡不佳時應用重連導致連接數(shù)漲太快,一般默認即可。
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 alsowait_timeout.
解釋:一個持續(xù)SLEEP狀態(tài)的線程多久被關閉。線程每次被使用都會被喚醒為acrivity狀態(tài),執(zhí)行完Query后成為interactive狀態(tài),重新開始計時。wait_timeout不同在于只作用于TCP/IP和Socket鏈接的線程,意義是一樣的。
MySQL可以配置連接的超時時間,這個時間如果做得太長,甚至到了10min,那么很可能發(fā)生這種情況,3000個鏈接都被占滿而且sleep在哪,新鏈接進不來,導致無法正常服務。因此這個配置盡量配置一個符合邏輯的值,60s或者120s等等。
說人話:
命令行下面敲一個命令后,直至下一個命令到來之前的時間間隔為interactive_time,如果這個時間間隔超過了 interactive_timeout,則連接會被自動斷開,下一個命令失敗。不過一般的mysql客戶端都有自動重連機制,下一個命令會在重連后執(zhí) 行。
[sql]
mysql> set interactive_timeout = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> show session variables like '%timeout%';
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| connect_timeout | 10 |
| interactive_timeout | 1 |
| wait_timeout | 28800 |
+----------------------------+----------+
10 rows in set (0.00 sec)
=====
[sql]
mysql> set wait_timeout = 1;
Query OK, 0 rows affected (0.00 sec)
【去泡杯茶,等會兒】
mysql> show session variables like '%timeout%';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 7
Current database: *** NONE ***
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| connect_timeout | 10 |
| interactive_timeout | 28800 |
| wait_timeout | 28800 |
+----------------------------+----------+
10 rows in set (0.01 sec)
wait_timeout:
The number of seconds the server waits for activity on a noninteractive connection (連接上沒有活動命令,可能是客戶端喝咖啡去了。)before closing it. Before MySQL 5.1.41, this timeout applies only to TCP/IP connections, not to connections made through Unix socket files, named pipes, or shared memory.
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
上述內(nèi)容就是MySQL中怎么設置查詢超時,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當前標題:MySQL中怎么設置查詢超時-創(chuàng)新互聯(lián)
URL網(wǎng)址:http://jinyejixie.com/article36/egppg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設、網(wǎng)站排名、網(wǎng)站營銷、品牌網(wǎng)站建設、外貿(mào)網(wǎng)站建設、用戶體驗
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容