Menu

MySQL Error 2013: Lost Connection During Query

Troubleshoot MySQL Error 2013 by distinguishing initial connection timeouts from query-time network drops, transfer stalls, and large packets.

Posted on By Updated on
On this page

MySQL client Error 2013 (HY000, CR_SERVER_LOST) commonly appears as Lost connection to MySQL server during query: the client did not receive a complete response. MySQL also documents a less common case during the initial connection when the server’s connect_timeout is too short. First identify whether the error occurred before a query started or while a query was running. See the MySQL 8.4 client error reference and lost-connection troubleshooting guide.

Start by noting which query was running, whether it was sending a large request or receiving a large result, and the time of the failure. Check the MySQL error log and ask the administrator whether the server restarted or closed the connection at that time.

If the query changed data, the client may not know whether MySQL completed the operation before the response was lost. Check the transaction or resulting data before retrying a non-idempotent write.

Check network and timeout settings

If Error 2013 occurs during a long-running query or while rows are being transferred, check the client application’s read timeout and any proxy, load balancer, VPN, or firewall idle timeout between the client and server. Reproduce the problem from the same host and application environment; a network path can behave differently from a local MySQL client.

An administrator can inspect the MySQL network timeout and packet settings:

SHOW GLOBAL VARIABLES
WHERE Variable_name IN (
  'net_read_timeout',
  'net_write_timeout',
  'max_allowed_packet'
);

net_read_timeout controls how long the server waits for more data from the client; net_write_timeout controls how long it waits to write a block to the client. Check the setting that matches the direction of the stalled transfer before changing timeouts. See the MySQL 8.4 system variable documentation and troubleshooting guide for lost connections.

If no query began and the failure occurred while establishing a connection, check the server’s Aborted_connects counter and connect_timeout instead:

SHOW GLOBAL STATUS LIKE 'Aborted_connects';
SHOW GLOBAL VARIABLES LIKE 'connect_timeout';

Aborted_connects increases when the server aborts an initial connection attempt. Only consider increasing connect_timeout if the server is reached over a legitimately slow or long-distance network; it does not fix query-time read or write stalls.

Check for large requests or results

If the query sends a large statement, inserts many rows in one batch, or returns large BLOB values, compare the client and server max_allowed_packet limits. Try reducing the batch size or retrieving results in smaller pages. Increase a packet limit only when the workload requires it and the database administrator has checked the memory and client-side limits.

For a long SELECT, test a smaller result or narrower column list. If only one large query fails, inspect that query and the server log rather than raising every timeout globally.

Error 2013 versus Errors 2006 and 2003

  • Error 2013 (CR_SERVER_LOST): the client did not receive a complete response while a query was running.
  • Error 2006 (CR_SERVER_GONE_ERROR): the client could not send a request on a connection that had already become unusable; see MySQL Error 2006 troubleshooting.
  • Error 2003 (CR_CONN_HOST_ERROR): the client could not establish the initial connection to the specified host and port; see MySQL Error 2003 troubleshooting.

For other connection, authentication, and SQL failures, browse the MySQL error troubleshooting index.