首頁  >  文章  >  資料庫  >  MySQL和相關的timeout詳細解析

MySQL和相關的timeout詳細解析

小云云
小云云原創
2017-12-22 13:27:451685瀏覽

查詢mysql函式庫時, 在資料量比較大時,會話總斷。剛開始以為是mysql的和連接有關timeout的問題,結果是網路的不穩定的原因。 本文主要介紹了MySQL和連接相關的timeout 的詳細整理的相關資料,本文主要總結下和連接有關的timeout,需要的朋友可以參考下,希望能幫助大家。

下面總結下方和連線相關的timeout 

slave-net-timeout

The number of seconds to wait for more data from the master before the slave considers the connection broken, aborts the read, and tries to reconnect. The first retry occurs immediately after the timeout. The interval between retries is controlled by the MASTER_CONed by the MASTER CONed. number of reconnection attempts is limited by the --master-retry-count option. The default is 3600 seconds (one hour).
當slave認為連接master的連接有問題時,就等待N秒,然後斷開連接,重新連接master

net_read_timeout :

The number of seconds to wait for more data from a connection before aborting the read. When the server is reading from the client, net_read_timeout is the timeout value controlling when to abort
在終止讀取之前,從一個連接獲得資料而等待的時間秒數;當服務正在從客戶端讀取資料時,net_read_timeout控制何時逾時。

net_write_timeout:

#The number of seconds to wait for a block to be written to a connection before aborting the write.When the server is writing to the client, net_write_timeout is the timeout value controlling when to abort。
在終止寫之前,等待多少秒把block寫到連線;當服務正在寫資料到客戶端時,net_write_timeout控制何時逾時

wait_timeout

#The number of seconds the server waits for activity on a noninteractive connection before closing it.
與伺服器端無互動狀態的連接,直到被伺服器端強制關閉而等待的時間

interactive_timeout :

The number of seconds the server waits for activity on an interactive connection before closing it.
與伺服器端無互動狀態的連接,直到被伺服器端強制關閉而等待的時間

connect_timeout

The number of seconds that the mysqld server waits for a connect packet before responding with Bad handshake. The default value is 10 seconds.

等待一個連接回應的時間 

connect_timeout:在取得連線階段(authenticate)起作用

interactive_timeout和wait_timeout:在連線空閒階段(sleep)起作用
net_read_timeout和net_write_timeout:則是在連線繁忙階段(query)起作用。

取得MySQL連線是多次握手的結果,除了使用者名稱和密碼的符合校驗外,還有IP->HOST->DNS->IP驗證,任何步驟都可能因為網路問題導致線程阻塞。為了防止執行緒浪費在不必要的校驗等待上,超過connect_timeout的連線請求將會被拒絕。 

即使沒有網路問題,也無法允許用戶端一直佔用連線。對於保持sleep狀態超過了wait_timeout(或interactive_timeout,取決於client_interactive標誌)的客戶端,MySQL會主動斷開連線。

即使連線沒有處於sleep狀態,也就是客戶端忙於運算或儲存數據,MySQL也選擇了有條件的等待。在資料包的分發過程中,客戶端可能來不及回應(發送、接收、或處理資料包太慢)。為了確保連線不會浪費在無盡的等待中,MySQL也會選擇有條件(net_read_timeout和net_write_timeout)地主動斷開連線。

相關推薦:

JavaScript中setTimeout之單執行緒

實例解譯setTimeout看出js函數執行過程

js中的setTimeout()函數

以上是MySQL和相關的timeout詳細解析的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn