標籤:
mysql 用戶端串連伺服器,用戶端報對應的錯誤號碼總結:
1. Error 104
[email protected]:~$perror 104
OS error code 104: Connection reset by peer
這個是由於server端 backlog 滿了 導致。
2. Error 110
[email protected]:~$perror 110
OS error code 110: Connection timed out
這個是與server端 串連時 逾時 導致。逾時時間超過了用戶端time out。
3. Error 111
[email protected]:~$perror 111
OS error code 111: Connection refused
這個是與server端 串連,被server串連拒絕,說明這個連接埠不處於監聽狀態,或該連接埠不開放導致。
4. Error 4
[email protected]:~$perror 4
OS errorcode 4: Interrupted system call
這個說明,用戶端發起第一個tcp包(syn包),在用戶端設定的時間內,沒有得到響應。在沒有超過用戶端的timeout時間(也有其它原因,比如檔案控制代碼不夠也會被OS斷開這次串連),用戶端被OS斷開了。
重點說明下 error 4
[email protected]:~$mysql -hlongxibendi-cd-pa-abcd00 -P3309 --connect-time=5
ERROR 2003 (HY000): Can‘t connect to MySQL server on‘longxibendi-cd-pa-abcd00‘ (4)
[email protected]:~$time mysql -hlongxibendi-cd-pa-abcd00 -P3306 --connect-time=8
ERROR 2003 (HY000): Can‘t connect to MySQL server on‘longxibendi-cd-pa-abcd00‘ (4)
real 0m8.006s
user 0m0.004s
sys 0m0.001s
[email protected]:~$mysql -hlongxibendi-cd-pa-abcd00 -P3309 --connect-time=10
ERROR 2013 (HY000): Lost connection to MySQL server at ‘readinginitial communication packet‘, system error: 110
用戶端與server進行串連,串連重試次數,取決於/proc/sys/net/ipv4/tcp_syn_retries 這個參數(測試的伺服器,該參數=1)
這樣,用戶端,第一次發起串連,持續3s,不成功,進行第一次重試,持續6s,如果不成功,則被OS斷開。
所以,在設定為 connect-time=5、8s 的二次測試中,都是因為,第一次重試,重試還沒完成,但超過connect-time時間,用戶端被OS斷開。(因為要完成第一次重試,至少需要9s,而connect-time小於9s)。故而報 error 4 。
在設定為connect-time=10s的測試中,用戶端第一次發起串連,持續3s,不成功,進行第一次重試,重試完,還沒成功,到達connect-time時間,用戶端斷開。故而報 error 110 。
總結下,假設 /proc/sys/net/ipv4/tcp_syn_retries的值為 n
則,在 tcp發起串連時,先發送syn包,在沒有超過 connect-time 之前,依次重試時間間隔規律為
3s 6s 12s 24s 48s
0次 第1次 第2次 第3次 第4次
第0次,發syn包,持續3s等響應,如果沒有,重試第1次,發送syn包,持續6s,如果沒有重試第2次,發syn包,持續12s,依次類推
總花費時間為:
傳輸時間+間隔時間=傳輸時間 + 3*[1*(1-2n)/(1-2) + 2 n]=3 (2n+1 - 1 ) + 傳輸時間
因為傳輸時間基本為0s
所以省略傳輸時間,總花費時間大概為 3 (2n+1 - 1 ) 秒
mysql client常見error總結