MySQL Connection Drops: max_allowed_packet, wait_timeout & OS OOM Killer Forensics
Diagnosing drops from oversized packets exceeding max_allowed_packet, wait_timeout socket termination, and Linux OOM killer termination of mysqld.
Operational Verification & Reliability Metadata
The error string is a symptom, not the root cause. Do not restart the server blindly. Run the diagnostic queries below to pinpoint the actual failure mode.
▸Symptom
Applications encounter abrupt connection loss during payload transfer:
ERROR 2006 (HY000): MySQL server has gone away
ERROR 2013 (HY000): Lost connection to MySQL server during query▸What You See in Production
Uploading large JSON documents or BLOBs fails immediately, or dormant background workers crash upon resuming operations.
▸Root Cause Matrix
| Probability | Root Cause | Description |
|---|---|---|
| %50 | `max_allowed_packet` Exceeded | Outgoing statement size exceeds server's packet buffer limit. |
| %30 | `wait_timeout` Inactivity Severance | Idle connection exceeds server timeout threshold and gets closed. |
| %20 | Kernel OOM Killer | Operating system kills mysqld under severe RAM exhaustion. |
▸EMERGENCY RUNBOOK (0-5 min)
# 1. Check for OS OOM terminations
dmesg -T | grep -i oom
# 2. Expand packet buffer size dynamically to 256MB
mysql -u root -p -e "SET GLOBAL max_allowed_packet = 256 * 1024 * 1024;"
# 3. Increase idle socket timeouts
mysql -u root -p -e "SET GLOBAL wait_timeout = 600; SET GLOBAL interactive_timeout = 600;"▸PERMANENT BLUEPRINT
- 1my.cnf Settings: Enforce
max_allowed_packet = 256Mpermanently. - 2Connection Pool Validation: Enable active connection test ping on borrow.
- 3Memory Safeguards: Budget buffer pool below 70% of total host RAM.
▸Verification
SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet';
SHOW GLOBAL VARIABLES LIKE 'wait_timeout';Other Database Error Triage Playbooks
Other battle-tested diagnostic guides for high-severity database errors.
MySQL ERROR 1045 Access denied: root Password Reset Guide
Four causes of MySQL 1045, meaning of using password: YES/NO, and safe credential recovery via --init-file.
MySQL Deadlock ERROR 1213: Graph Analysis and Permanent Prevention
Root causes of MySQL 1213 deadlock, parsing LATEST DETECTED DEADLOCK output, gap lock concurrency issues, and resilient application retry design.
MySQL Lock wait timeout exceeded: Finding Blocking Sessions
Finding the blocking transaction using performance_schema, safe KILL decision matrices, and permanent locking reduction.