MySQLMySQL 2006
MySQL 2006: MySQL Server Has Gone Away
MySQL 2006 means the client lost its connection to the server mid-query. The server closed the connection because the query or result exceeded the allowed packet size, or because the connection was idle for too long.
Example Query
-- Large BLOB insert exceeding max_allowed_packet:
INSERT INTO files (data) VALUES (LOAD_FILE('/path/to/large_file.bin'));Common Causes
- 1Query or result set exceeds max_allowed_packet (default 4 MB)
- 2Connection idle timeout (wait_timeout) exceeded before the query was sent
- 3Server restarted or crashed during a long-running query
How to Fix It
Increase max_allowed_packet in my.cnf: max_allowed_packet=64M. Increase wait_timeout for long-running batch jobs. Add reconnection logic in the application. Chunk large BLOB inserts into smaller transactions.
Need a reliable database?
Try Supabase — free PostgreSQL with a generous free tier. No credit card required.
Got a query causing this error?
Paste it into SQLbuddy and get an instant plain-English explanation with optimization tips.
Analyze My Query →