Got timeout reading communication packets解決方法
http://www.th7.cn/db/mysql/201702/225243.shtml
[Note] Aborted connection xxxx to db:
問題現象:在tail -f/data/logs/mysql/error.log日志中出現大量的如下信息(web用的是Zabbix,設置連接超時時間為100秒):
' host: 'localhost' (Got timeout reading communication packets)
2017-02-05T15:30:19.272811+08:00 28546 [Note] Aborted connection 28546 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
2017-02-05T15:30:22.388624+08:00 28547 [Note] Aborted connection 28547 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
2017-02-05T15:30:27.119216+08:00 28554 [Note] Aborted connection 28554 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
解決辦法:
修改[root@lovebuy114 ~]# grep timeout /etc/my.cnf
interactive_timeout = 120
wait_timeout = 120
log_warnings=1 //注意,我這里原來是2。修改成1后,問題現象果然但是已經不存在了。
在命令行中可以這樣修改:
mysql>set global log_warning=1;
mysql>set global interactive_timeout = 120;
mysql>set global wait_timeout = 120;
參數簡要說明:
1)interactive_timeout:
參數含義:服務器關閉交互式連接前等待活動的秒數。交互式客戶端定義為在mysql_real_connect()中使用CLIENT_INTERACTIVE選項的客戶端。
參數默認值:28800秒(8小時)
解決無Notice的辦法:
grep timeout /etc/my.cnf innodb_lock_wait_timeout = 60
interactive_timeout = 28800
wait_timeout = 22
grep log_warnings /etc/my.cnflog_warnings=2
From:http://blog.csdn.net/jamesyao008/article/details/45098073
修改后,無效,原因是現在是變成了Notice,不是警告:
tail -f/data/logs/mysql/error.log
2017-02-05T15:38:19.678134+08:00 128 [Note] Aborted connection 128 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
2017-02-05T15:38:22.452504+08:00 131 [Note] Aborted connection 131 to db: 'zabbix' user: 'zabbix' host: 'localhost' (Got timeout reading communication packets)
連接、網絡類超時
http://www.cnblogs.com/xiaoboluo768/p/6222862.html
共有如下幾個:
connect_timeout:默認為10S
wait_timeout:默認是8小時,即28800秒
interactive_timeout:默認是8小時,即28800秒
net_read_timeout:默認是30S
net_write_timeout:默認是60S
msg:MySQL server has gone away
handshake流程
在TCP三次握手的基礎之上,簡歷MySQL通訊協議的連接,這個連接建立過程受connect_timeout參數控制
--------------------TCP established--------------------
MySQL Server(10.10.20.96)------->Client(10.10.20.51)
Client(10.10.20.51)------->MySQL Server(10.10.20.96)
MySQL Server(10.10.20.96)------->Client(10.10.20.51)
--------------------established--------------------
在MySQL通訊協議建立連接之后,此時客戶端連接的超時受wait_timeout和interactive_timeout參數控制
建立連接后無交互:MySQL server ---wait_timeout--- Client
建立連接交互后:MySQL server ---interactive_timeout--- Client
在如果客戶端有數據包傳輸,那么這個數據包的傳輸超時由net_read_timeout和net_write_timeout參數控制
-------------------client與server端有數據傳輸時-------------------
client ----->MySQL Server(net_read_timeout)
client <-----MySQL Server(net_write_timeout)
從上面的結果中可以看到,第一個會話中修改global wait_timeout=5之后,新的連接上來,超過5秒沒有發送新的數據包,連接就被斷開。
net_write_timeout
mysql服務端向客戶端寫(發送)數據時,服務端等待客戶端響應的超時時間,當服務端正在寫數據到客戶端時,net_write_timeout控制何時超時
net_read_timeout
mysql服務端從客戶端讀取(接收)數據時,服務端等待客戶端響應的超時時間,當服務端正在從客戶端讀取數據時,net_read_timeout控制何時超時
MySQL · 答疑解惑 · MySQL 的那些網絡超時錯誤
http://mysql.taobao.org/monthly/2017/05/04/
阿里雲內核月報
前言
我們在使用/運維 MySQL 過程中,經常會遇到一些網絡相關的錯誤,比如:
Aborted connection 134328328 to db: 'test' user: 'root' host: '127.0.0.1' (Got timeout reading communication packets)
MySQL 的網絡超時相關參數有好幾個,這個超時到底是對應哪個參數呢?
在之前的月報中,我們介紹過 MySQL 的 網絡通信模塊 ,包括各模塊間的關系,數據網絡包是如何發送接受的,以及結果集的數據格式,大家可以先回顧下。
這里我們對 mysqld 處理網絡包時,遇到的超時異常情況進行分析,希望大家在遇到網絡相關的報錯時,能更好理解和排查問題。
問題分析
MySQL 是平等網絡協議,就是說 client 和 server 之間的網絡交互是一來一回的,client 發送完請求后,必須等待 server 響應包回來,才能發下一個請求。
對 mysqld 來說,就是接收網絡請求,然后內部處理,將結果集返回給客戶端,然后等待下一個請求:
先看下 mysqld server 和網絡超時相關的參數有哪些:
interactive_timeout
wait_timeout
net_read_timeout
net_write_timeout
connect_timeout
在底層實現上,不管是讀還是寫操作,超時都是通過 poll(&pfd, 1, timeout) 做的,參數之間的區別是針對連接的不同狀態。
讀超時
wait_timeout 是給讀請求用的,在 do_command 開始就做設置:
my_net_set_read_timeout(net, thd->variables.net_wait_timeout);
這個時候,連接是空閑的,等待用戶的請求。
等讀完用戶的請求包后,連接就變成 active 的,在調用 dispatch_command 執行 SQL 前,通過
my_net_set_read_timeout(net, thd->variables.net_read_timeout);
把超時設置回 net_read_timeout,之后在執行 SQL 請求過程中,server 和 client 基本不會有網絡交互,所以這個超時基本用不上。
有一個特殊的情況是 LOAD DATA LOCAL FILE 命令,server 在執行過程中,需要和 client 再做網絡交互。
interactive_timeout 是給交互模式的客戶端使用的,比如我們常用的 mysql client 工具,這個是在認證過程中設置的,邏輯如下:
static void
server_mpvio_update_thd(THD *thd, MPVIO_EXT *mpvio)
{
thd->client_capabilities= mpvio->client_capabilities;
thd->max_client_packet_length= mpvio->max_client_packet_length;
if (mpvio->client_capabilities & CLIENT_INTERACTIVE)
thd->variables.net_wait_timeout= thd->variables.net_interactive_timeout;
thd->security_ctx->user= mpvio->auth_info.user_name;
if (thd->client_capabilities & CLIENT_IGNORE_SPACE)
thd->variables.sql_mode|= MODE_IGNORE_SPACE;
}
如果客戶端的能力位上設置了 CLIENT_INTERACTIVE,會用 interactive_timeout 的值覆蓋 wait_timeout 的值。
而一般情況下,我們應用在建立連接時,是不會設置這個能力位的。
寫超時
net_write_timeout 對應寫超時,在連接認證完成后,server 和 client 交互過程中寫超時一真是不變的。
認證超時
connect_timeout 是給連接認證過程用的,讀和寫都用這個值,認證完成后,讀和寫分別設置為 net_read_timeout 和 net_write_timeout。
總結
可以看到和讀相關的超時參數是最多的,也比較容易搞混亂。
如果是認證過程中超時,不管是讀還是,都是 connect_timeout;
對於讀網絡超時,一般是 wait_timeout/interactive_timeout,基本不會是 net_read_timeout(特例是業務用到 LOAD DATA LOCAL FILE);
對於寫網絡超時,都是 net_write_timeout。
在遇到超時情況下,可以根據這些原則判斷對那個參數做調整。
比如下面這種情況:
2017-05-15 19:32:41 47930 [Warning] Aborted connection 6 to db: 'unconnected' user: 'root' host: 'localhost' (Got timeout reading communication packets)
很可能需要調整的 wait_timeout/interactive_timeout。
2017-05-15 20:06:27 5063 [Warning] Aborted connection 12 to db: 'test' user: 'root' host: 'localhost' (Got timeout writing communication packets)
需要調整 net_write_timeout
需要注意的是,MySQL 的關於網絡的錯誤,除了超時以外都認為是 error,沒有做進一步的細分,比如可能會看到下面這種日志,有可能是客戶端異常退出了,也有可能是網絡鏈路異常。
2017-05-15 19:34:57 47930 [Warning] Aborted connection 8 to db: 'unconnected' user: 'root' host: 'localhost' (Got an error reading communication packets)
2017-05-15 20:07:39 5063 [Warning] Aborted connection 13 to db: 'test' user: 'root' host: 'localhost' (Got an error writing communication packets)
f