The client tried to read from or write to MySQL, but the server had already closed the TCP connection.
MySQL Error 2006: CR_SERVER_GONE_ERROR happens when the server closes a client connection or the network drops. Check server logs, raise wait_timeout and max_allowed_packet, then reconnect to resolve the issue.
MySQL server has gone away
MySQL error 2006 appears when a client issues a request but the TCP socket to the MySQL server is already closed. The client library detects the broken pipe and throws CR_SERVER_GONE_ERROR with the message "MySQL server has gone away."
The disconnect usually results from server timeouts, oversized packets, crashes, or network interruptions.
Fixing the root cause restores reliable connectivity and prevents data-loss scenarios.
Idle sessions that exceed wait_timeout
or interactive_timeout
are silently closed by mysqld. The next statement sent by the client fails with error 2006.
Queries or BLOB transfers bigger than max_allowed_packet
make the server abort the session to avoid memory exhaustion, triggering the error.
Slow queries can hit net_read_timeout
or net_write_timeout
.
When the client waits too long for a response it assumes the server is gone.
Server restarts, OOM kills, firewall resets, or flaky VPN links break open sockets instantly, so every client sees CR_SERVER_GONE_ERROR on the next operation.
Inspect the MySQL error log for "Aborted connection" or packet-size messages to locate the trigger.
The log shows the user, host, and SQL involved.
Raise wait_timeout
, interactive_timeout
, net_read_timeout
, net_write_timeout
, and max_allowed_packet
temporarily, then repeat the failing workload to confirm stability.
Refactor long-running statements or batch uploads so they stay within packet limits and finish before timeouts expire.
Enable automatic reconnect in drivers (autoReconnect=true
in JDBC, MYSQL_OPT_RECONNECT
for C, or autoreconnect=True
in Python) so transient drops self-heal.
A web page that runs a giant SELECT times out and shows "server has gone away." Paginating the query or adding indexes removes the error.
An ETL script fails on a 300 MB INSERT.
Executing SET GLOBAL max_allowed_packet = 1073741824;
(1 GB) lets the load finish.
A cron job idles two hours then queries the DB. Adding a SELECT 1
heartbeat every five minutes or reopening the connection resolves the failure.
Use connection pooling and close idle handles quickly. Short-lived sessions lower the chance of hitting timeout limits.
Size wait_timeout
and max_allowed_packet
to real workload patterns, not default values.
Review them after every schema or traffic change.
Monitor Aborted_clients
, Aborted_connects
, and Threads_connected
with Galaxy dashboards or other observability tools, alerting on spikes.
Leverage Galaxy's query history to identify slow, heavy queries and refactor them before they cause disconnects.
Error 2013 "Lost connection to MySQL server during query" occurs when the link dies while streaming results.
The fixes mirror error 2006.
Error 2055 "Lost connection to MySQL server at '%s', during handshake" points to SSL or DNS issues in the initial handshake.
Error 1040 "Too many connections" means mysqld refused new clients rather than dropping existing ones. Increase max_connections
or use pooling.
.
The server closes connections that sit idle past wait_timeout
or interactive_timeout
. The next statement fails with error 2006.
A packet larger than max_allowed_packet
makes mysqld abort the connection, returning CR_SERVER_GONE_ERROR.
Mysqld restarts or crashes close all sockets.
Clients attempt to reuse them and receive the error.
Transient outages, VPN drops, or firewalls that silently drop idle TCP sessions yield error 2006 when data is next exchanged.
.
It prevents idle disconnects but will not fix packet size issues or server crashes. Diagnose the log before changing the value.
A high limit consumes more memory per connection. Set it only when importing large data and reduce it afterward.
Galaxy surfaces slow or oversized queries, lets you tune parameters, and provides keepalive snippets, lowering disconnect risk.
Yes. When the session is recreated, any uncommitted work is rolled back. Commit frequently if you rely on auto reconnect.