客戶端與 Server 之間的 TCP 連接在查詢執行過程中意外斷開,非正常關閉(如 mysql_close())。
| 類別 | 具體原因 | 排查/解決 |
|---|---|---|
| 網絡/連接層 | 防火牆/網關空閒超時切斷長連接 | 啟用客戶端/連接池 autoReconnect=true、心跳機制;調整防火牆超時 |
客戶端 wait_timeout/interactive_timeout 過小 | Server 默認 8h,若修改過請檢查;連接池配置 testOnBorrow + validationQuery | |
| 網絡抖動、交換機/路由器故障 | Ping/TCping 監控、抓包分析 | |
| 查詢/數據層 | 單條 SQL 執行時間超過 net_read_timeout/net_write_timeout(默認 30s/60s) | 優化慢查詢、加索引、分頁、拆分大事務;調大超時參數 |
結果集過大,超過 max_allowed_packet(默認 4MB/64MB) | 增大 max_allowed_packet(Server 與 Client 同調);分批獲取 | |
| Blob/Text 大字段讀取慢 | 避免 SELECT *,按需選列;啟用壓縮協議 | |
| 服務器端異常 | OOM Killer 殺死 mysqld 進程 | 檢查 /var/log/messages Out of memory;調整 innodb_buffer_pool_size、限制連接數 |
| mysqld 崩潰重啟 | 查看錯誤日志 .err,搜索 Assertion failure、Signal 11 等 |
SHOW GLOBAL STATUS LIKE 'Aborted_connects'; 觀察計數增長。FIN/RST 包及發送方。testOnBorrow=true、validationQuery=SELECT 1、eviction 定期清理空閒連接。?autoReconnect=true&failOverReadOnly=false&maxReconnects=3。wait_timeout=28800、net_read_timeout=60、net_write_timeout=60、max_allowed_packet=64M。Threads_connected、Aborted_clients、Max_used_connections。