久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

MySQL中怎么設(shè)置查詢超時(shí)

共計(jì) 3174 個(gè)字符,預(yù)計(jì)需要花費(fèi) 8 分鐘才能閱讀完成。

本篇文章為大家展示了 MySQL 中怎么設(shè)置查詢超時(shí),內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

為了優(yōu)化 OceanBase 的 query timeout 設(shè)置方式,特調(diào)研 MySQL 關(guān)于 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)
重點(diǎn)解釋其中幾個(gè)參數(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 lsquo;XXX rsquo;, system error: errno.
解釋:在獲取鏈接時(shí),等待握手的超時(shí)時(shí)間,只在登錄時(shí)有效,登錄成功這個(gè)參數(shù)就不管事了。主要是為了防止網(wǎng)絡(luò)不佳時(shí)應(yīng)用重連導(dǎo)致連接數(shù)漲太快,一般默認(rèn)即可。
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.
解釋:一個(gè)持續(xù) SLEEP 狀態(tài)的線程多久被關(guān)閉。線程每次被使用都會(huì)被喚醒為 acrivity 狀態(tài),執(zhí)行完 Query 后成為 interactive 狀態(tài),重新開始計(jì)時(shí)。wait_timeout 不同在于只作用于 TCP/IP 和 Socket 鏈接的線程,意義是一樣的。
MySQL 可以配置連接的超時(shí)時(shí)間,這個(gè)時(shí)間如果做得太長(zhǎng),甚至到了 10min,那么很可能發(fā)生這種情況,3000 個(gè)鏈接都被占滿而且 sleep 在哪,新鏈接進(jìn)不來,導(dǎo)致無法正常服務(wù)。因此這個(gè)配置盡量配置一個(gè)符合邏輯的值,60s 或者 120s 等等。
說人話:
命令行下面敲一個(gè)命令后,直至下一個(gè)命令到來之前的時(shí)間間隔為 interactive_time,如果這個(gè)時(shí)間間隔超過了 interactive_timeout,則連接會(huì)被自動(dòng)斷開,下一個(gè)命令失敗。不過一般的 mysql 客戶端都有自動(dòng)重連機(jī)制,下一個(gè)命令會(huì)在重連后執(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)
【去泡杯茶,等會(huì)兒】
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 (連接上沒有活動(dòng)命令,可能是客戶端喝咖啡去了。)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 中怎么設(shè)置查詢超時(shí),你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注丸趣 TV 行業(yè)資訊頻道。

正文完
 
丸趣
版權(quán)聲明:本站原創(chuàng)文章,由 丸趣 2023-08-04發(fā)表,共計(jì)3174字。
轉(zhuǎn)載說明:除特殊說明外本站除技術(shù)相關(guān)以外文章皆由網(wǎng)絡(luò)搜集發(fā)布,轉(zhuǎn)載請(qǐng)注明出處。
評(píng)論(沒有評(píng)論)
主站蜘蛛池模板: 长岭县| 秦皇岛市| 苏尼特右旗| 盱眙县| 巫山县| 惠来县| 武山县| 宿州市| 平山县| 永昌县| 九江县| 运城市| 石阡县| 周口市| 凌源市| 虎林市| 平罗县| 衢州市| 额敏县| 绥化市| 遵义市| 关岭| 宁德市| 横山县| 南和县| 邹平县| 丰原市| 南京市| 望江县| 仙居县| 肇东市| 阿勒泰市| 康保县| 雷波县| 连平县| 金溪县| 景谷| 苍山县| 孟村| 洪雅县| 瓦房店市|