MySQL Error 2013: Lost Connection During Query
Troubleshoot MySQL Error 2013 by checking network drops, server logs, transfer timeouts, and large results, then verify writes before retrying.
On this page
MySQL client Error 2013 (HY000, CR_SERVER_LOST) means the client did not receive a complete response to a query. The usual message is Lost connection to MySQL server during query. The MySQL 8.4 client error reference defines the code and message.
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.
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.