Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsIf MySQL reports “Lost connection to MySQL server during query”, the immediate fix depends on when the connection broke. Error 2013 (CR_SERVER_LOST) can mean a network interruption, a timeout during the initial handshake, a result that took too long to transfer, an oversized packet, a server restart, or a stale connection reused from a pool. Verify the server and endpoint first, classify the failure phase, then change only the matching timeout, packet limit, network policy, or pool behavior.
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
The same investigation also explains “MySQL server has gone away” and other communications-link failures. The sections below give a reproducible sequence for error 2013, including what to change for max_allowed_packet, wait_timeout, connect_timeout, net_read_timeout, and net_write_timeout.
As an Amazon Associate I earn from qualifying purchases.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11What error 2013 means
MySQL error 2013, named CR_SERVER_LOST, is the client-side message “Lost connection to MySQL server during query”. It describes a broken client-server conversation, not one specific defect. The break can happen while the client is opening a connection, during handshake and authorization, while a statement is executing, while rows are being sent, or when an application reuses a connection that sat idle in a pool.
“MySQL server has gone away” is a closely related symptom. A server timeout, a network device closing an idle TCP session, a server crash, a packet larger than an allowed limit, or a wrong host, port, or socket can all produce a similar application error. Timing and the server logs are more useful than the wording alone.
#1 Best Overall
Read the phase from the error
| When it fails | Most likely areas | First evidence to collect |
|---|---|---|
| Immediately, with text about reading an authorization packet | DNS, routing, wrong endpoint, overloaded server, or connect_timeout |
Resolved address, configured port or socket, connection timestamp, and server error log |
| Only while a statement runs or rows are returned | Network interruption, slow transfer, net_read_timeout, net_write_timeout, or a server restart |
Query duration, result size, client read/write timeout, and mysqld log entries |
| Only for large BLOBs, long strings, or bulk INSERT/REPLACE statements | max_allowed_packet on the client or server, or an impractically large batch |
Approximate statement/row size and both sides’ packet settings |
| After a predictable idle period, especially in a pool | wait_timeout, interactive_timeout, firewall or load-balancer idle policy, or stale pooled sockets |
Idle duration, pool age, network-device policy, and Aborted_clients |
| At every attempt | mysqld stopped, wrong host/port/socket, DNS failure, firewall rejection, or a crashed server | Process status, listener, endpoint configuration, and restart history |
Step 1: Confirm mysqld and the endpoint
Do not begin by increasing a timeout. MySQL’s connection troubleshooting sequence starts by proving that the server is running and that the client is addressing the right listener.
- Check server availability. On the database host, verify that the
mysqldservice is running and inspect its error log for a crash, out-of-memory event, or restart at the failure time. In a managed service, obtain the equivalent health and restart events from the provider. - Confirm the exact endpoint. Record the hostname, resolved address, TCP port, named pipe, or Unix socket used by the application. Compare it with the listener configured by MySQL. A valid server on another port does not help a client pointed at the wrong one.
- Test from the same machine and network as the application. Use the normal MySQL client or driver with the same host, port, TLS settings, and account. A test from an administrator’s laptop can bypass the firewall, route, DNS view, or load balancer that affects the application.
- Check name resolution and routing. Confirm that the hostname resolves consistently and that traffic reaches the expected address. Investigate firewall rules, security groups, load-balancer health, TCP resets, faulty switches, and damaged cables where those apply.
If the endpoint is wrong or mysqld is down, correct that condition and retest before changing any MySQL variable.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Step 2: Classify the disconnect precisely
Capture the complete client exception, not just its first line. Note whether it says “during query,” “reading authorization packet,” “connection reset,” or “server has gone away.” Record the timestamp in UTC, the host and port or socket, the query identifier if available, whether the connection was newly opened or reused, and how long it had been idle.
Compare a deliberately small request with the failing request. A simple query that succeeds while a large result, BLOB, or bulk write fails points toward transfer timeouts or packet size. A failure after a stable idle interval points toward server or network idle policies. A failure before authentication points toward endpoint, DNS, load, or connect-timeout issues.
Step 3: Use logs and status counters
Inspect the MySQL server error log at the exact failure time. For more detail, MySQL recommends setting log_error_verbosity to 3 while diagnosing. Return to your normal logging policy after the investigation if volume or sensitive-data exposure is a concern.
Check the connection counters before and after a controlled reproduction:
Aborted_connectscounts failed initial connections, helping distinguish handshake and authorization problems.Aborted_clientsrises when clients disconnect improperly or connections are closed after being established, which is useful for idle-pool and interrupted-session investigations.- Server restart messages, crash reports, and out-of-memory events can explain a simultaneous loss of many sessions.
Useful read-only queries include:
SHOW GLOBAL STATUS LIKE 'Aborted_connects';
SHOW GLOBAL STATUS LIKE 'Aborted_clients';
SHOW VARIABLES WHERE Variable_name IN
('connect_timeout','wait_timeout','interactive_timeout',
'net_read_timeout','net_write_timeout','max_allowed_packet',
'log_error_verbosity');
Save the values with the timestamp and workload details. A counter by itself is not proof of causation; correlate it with the error log and the client’s phase.
Fixes for network, firewall, DNS, and endpoint failures
Frequent lost connections usually indicate network connectivity trouble. Trace the complete path between application and database rather than treating MySQL as the only component. Verify DNS answers from the application host, routing, firewall and security-group rules, load-balancer health checks, TCP idle limits, and any device that can send a reset or silently drop an idle flow.
Correct a wrong port, socket, or host
Use the connection settings actually consumed by the running process; environment files and secret managers often override a local configuration. For a Unix-socket connection, confirm that the socket file exists and belongs to the intended instance. For TCP, confirm both the address and port. If a direct connection works but a load-balanced one fails, compare the balancer’s idle and health policies with the direct path.
Handle intermittent links
Capture packet-loss, reset, and latency evidence at the time of failure. Do not “solve” a dropped link by setting every timeout to a very large value: that can keep broken sockets open longer and consume connection capacity. Repair the path or adjust the specific idle policy when the evidence identifies one.
Fix “reading authorization packet” and initial connection timeouts
A message about reading the authorization packet occurs during the initial handshake. The documented Oracle MySQL default for connect_timeout is 10 seconds (2026 documentation). MySQL suggests increasing it when a slow or distant connection needs more time, but first check DNS latency, routing, TLS negotiation, server load, and authentication plugins.
Change the server value only when the phase matches
A temporary server-side change can be made by an account with the required administrative privilege:
Rank #3
SET GLOBAL connect_timeout = 30;
The new value affects new connection attempts; existing sessions are not retroactively extended. For a permanent setting, place the value in the instance’s MySQL configuration using the syntax supported by your deployment, then restart or reload according to that deployment’s procedure. Confirm the effective value with SHOW VARIABLES LIKE 'connect_timeout';.
Also inspect the client or driver’s connection timeout. If the client gives up before the server’s value, raising only the server setting cannot help. Conversely, an excessive timeout can make a dead endpoint take longer to fail, so choose a value justified by measured network and authentication time.
Fix slow queries and interrupted result transfers
For an active query or result transfer, distinguish the direction of travel. net_read_timeout governs how long the server waits to read more data from a client; Oracle MySQL documents a 30-second default (2026 documentation). net_write_timeout governs how long the server waits while writing data to the client. Client-side socket read and write timeouts must also allow the same workload to finish.
When to raise net_read_timeout
Consider a higher value when the server receives a very large request over a demonstrably slow or high-latency link, or when a client sends data in pauses. Check that the client is still alive and that the network is not dropping packets before raising it:
SET GLOBAL net_read_timeout = 120;
This changes the default for new sessions. A session that already has a session-level value may retain it, so inspect the effective value on the connection that runs the workload.
When to review net_write_timeout
Rows can be produced successfully yet fail while being written to a slow client. Review net_write_timeout, the client driver’s read timeout, and any proxy between them. Increasing only the server write timeout is ineffective if the client closes the socket first. Conversely, allowing indefinitely slow consumers can tie up server resources; pagination, streaming, or a smaller result can be safer than a very large timeout.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Reduce the transfer before increasing timeouts
- Return only required columns and rows.
- Paginate or stream large result sets instead of materializing millions of rows at once.
- Investigate long-running queries separately with execution plans and indexes; a timeout setting does not make an inefficient query faster.
- Retest with the same client, route, and result size after each narrow change.
Fix “MySQL server has gone away” after idle time
MySQL normally closes an inactive noninteractive connection after 8 hours by default; the configurable server variable is wait_timeout (Oracle MySQL documentation, 2026). Interactive sessions use interactive_timeout when applicable. Firewalls, routers, and load balancers often impose a shorter idle limit, and Connector/J documentation notes that the MySQL protocol does not automatically ping an idle connection.
Make pooled connections safe to reuse
- Measure the age and idle duration of connections when the error occurs.
- Configure the pool to validate a connection before checkout, using the driver’s supported validation mechanism or a lightweight
/* ping */query. - Retire or recycle connections before the shortest known server or network idle limit.
- Enable TCP keepalive where it is appropriate and supported, while recognizing that keepalive settings differ by operating system and network policy.
- Set the pool’s client read/write and connection timeouts deliberately; do not let dead sockets remain indefinitely.
Raising wait_timeout can help only when the server is the component closing an otherwise healthy idle session. It does nothing for a firewall that expires the flow earlier. Lowering pool lifetime or adding validation is often safer than keeping every socket open for hours.
Reconnect without duplicating a transaction
A reconnect is not automatically safe. If the disconnect happened during a write, the server may have committed the transaction even though the client did not receive the response. Retry only operations designed to be idempotent, use transaction boundaries that the application can reconstruct, and record an idempotency key or outcome check where duplicate writes would be harmful. Never blindly replay an unknown transaction merely because error 2013 was returned.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Fix packet-size failures and oversized BLOBs
A MySQL communication packet can contain one SQL statement, one returned row, or a replication event. If either the client or mysqld receives a packet larger than max_allowed_packet, MySQL issues ER_NET_PACKET_TOO_LARGE and closes the connection. Both sides have a limit and the effective client limit may come from the connector rather than the server.
Free tools Windows power users keep installed
One-click scans. No signup required.
Oracle MySQL documents a 64 MB server default (2026 documentation), while the protocol maximum is 1 GB. The protocol maximum is not a recommendation: large limits increase potential memory use and do not cure a poor batching strategy.
Measure before changing the limit
Estimate the largest statement, parameter payload, individual BLOB, and returned row. A multi-row INSERT can exceed the limit even when each row is small. Compare a single-row write with the failing batch; if the small write succeeds and the large one fails, packet size or batch duration is a strong lead.
Best Value
Align client and server settings
Inspect the server value:
SHOW VARIABLES LIKE 'max_allowed_packet';
Increase the server and connector limits together only when the workload requires it, and leave headroom for concurrent operations. The exact client option name varies by driver, so use that driver’s documented configuration. After changing a global server value, establish a new connection and verify the effective client and server limits.
Prefer smaller batches when possible
- Split giant INSERT or REPLACE statements into bounded batches.
- Upload or process large objects in chunks supported by the application.
- Keep individual rows below the packet limit, including protocol and parameter overhead.
- Monitor memory and concurrency after raising the limit.
If the error is specifically ER_NET_PACKET_TOO_LARGE, increasing unrelated timeout variables will not solve it.
Client, server, network, or pool: choose the narrow fix
| Observed failure | Primary component | Target change | Main risk | Verification |
|---|---|---|---|---|
| Authorization packet timeout | Server, DNS, network, and client connect path | Correct endpoint; then align client timeout and connect_timeout |
Longer waits for dead endpoints | Handshake succeeds and Aborted_connects stops increasing during the test |
| Slow request upload | Network, client, server read path | net_read_timeout and client write timeout, or reduce request size |
Sessions remain occupied longer | Same payload completes without read-timeout log entries |
| Slow result download | Network, client, server write path | net_write_timeout and client read timeout, or reduce result size |
More server resources held for slow consumers | Result completes; client and server logs show no reset |
| Failure after idle reuse | Pool and network/server idle policies | Validation, recycling, keepalive, or matched idle limits | Validation overhead or excess connection churn | No stale-socket failures after the measured idle interval |
| Large BLOB or bulk statement | Client and server packet limits, application batching | Align max_allowed_packet or reduce batch size |
Higher memory demand | Small and large test cases behave predictably; no packet-too-large error |
A controlled retest and evidence checklist
- Write down the original error number, full message, phase, timestamp, endpoint, driver and server versions, query or payload size, row count, and idle duration.
- Capture the relevant server variables and the
Aborted_connectsandAborted_clientscounters. - Reproduce with a small request and then the failing workload from the application network.
- Apply one narrow change: endpoint, network policy, matching timeout, pool validation, packet limit, or batch size.
- Retest the identical workload and compare error-log entries, counters, latency, and resource use.
- Make a tested setting persistent through your deployment’s configuration management, document the reason and scope, and avoid retaining temporary diagnostic verbosity indefinitely.
If mysqld restarted, the error log indicates a crash, or failures remain after endpoint and network checks, preserve the log, configuration values, workload details, and restart timeline for a server or hosting support investigation. A precise timeline is more actionable than repeatedly increasing timeouts.
Quick answers to common questions
How do I stop MySQL error 2013?
Stop treating 2013 as a single bug. Identify whether it occurs at handshake, during transfer, after idle reuse, or only with oversized packets, then fix that phase and verify it with logs and counters.
Should I increase wait_timeout?
Only when the server is closing genuinely idle sessions and the application’s pool policy is otherwise sound. A firewall or router with a shorter idle limit requires pool validation, recycling, keepalive, or network-policy changes instead.
Is max_allowed_packet a client or server setting?
Both. The client and server enforce limits, so raising only one side can leave the connection failing. Smaller batches are preferable when they meet the application’s needs.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Why did a retry create duplicate data?
The connection can break after the server committed a write but before the client received its response. Retries must be transaction-aware and limited to idempotent operations or operations protected by an idempotency key.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




