Gaming industry under DDoS attack. Get DDoS protection now. Start onboarding
  1. Home
  2. Developers
  3. How to Fix Error 2006: MySQL Server Has Gone Away

How to Fix Error 2006: MySQL Server Has Gone Away

  • By Gcore
  • September 11, 2023
  • 2 min read
How to Fix Error 2006: MySQL Server Has Gone Away

Encountering the ‘Error 2006: MySQL Server Has Gone Away’ can be a disconcerting experience for many database administrators and developers. Often striking without warning, this error can disrupt database operations and bring your applications to a standstill. Understanding the underlying causes and knowing how to effectively address them is crucial. In this guide, we’ll delve deep into the root causes of this infamous MySQL error and provide actionable solutions to get your database running smoothly once again.

Fixing Error 2006: MySQL Server Has Gone Away

Here’s a step-by-step guide to fix this issue:

#1 Check Server Status

Verify that the MySQL server is running. If the server isn’t running, the client won’t be able to connect.

sudo systemctl status mysql

For the output, you’re looking for an “Active” status. If it’s “Inactive” or “Failed”, that’s a potential reason for the error.

#2 Increase ‘wait_timeout’ and ‘max_allowed_packet’ Values

These settings in MySQL configuration determine how long the server waits before closing a non-responsive connection and the maximum size of a packet that can be sent to the server, respectively.

  • Edit the MySQL configuration file.
sudo nano /etc/mysql/my.cnf
  • Add/Modify under [mysqld].
wait_timeout=28800max_allowed_packet=128M
  • Save and exit. For restarting MySQL run this command.
sudo systemctl restart mysql

#3 Check for Crashed Tables

Corrupt or crashed tables can cause connection issues. Run this command:

mysqlcheck -u root -p --all-databases

For the output, you will see a status for each table. Look for any that say “corrupt” or “crashed”.

#4 Review MySQL Error Logs

The logs can give a more in-depth look into any underlying issues causing the server to disconnect.

sudo tail -50 /var/log/mysql/error.log

On the output, look for any recent or recurring errors that might hint at the root cause.

#5 Monitor Server Resources

Insufficient resources can cause the MySQL server to become unresponsive.

top

For the output, review the %CPU and %MEM columns, particularly for the mysqld process. High resource usage might indicate resource constraints.

#6 Verify Disk Space

If the server’s disk is near or at capacity, MySQL might not operate correctly.

df -h

Review available space on the disk, especially for the partition where MySQL data is stored (typically /var/lib/mysql).

#7 Confirm Stable Network Connectivity

For remote MySQL connections, ensure there’s no network interruption between the client and server.

ping -c 5 <MySQL_SERVER_IP>

You should see replies from the server IP with minimal or no packet loss.

#8 Adjust Open Files Limit

MySQL can sometimes exceed the allowed open files limit of the system.

  • Edit the MySQL configuration.
sudo nano /etc/mysql/my.cnf
  • Add/Modify under [mysqld].
open_files_limit=5000
  • Save, exit, and restart MySQL.

After following these steps, try your operation again. If the error persists, you may need to delve deeper, considering factors like firewall configurations, specific application queries, or even potential bugs in the MySQL version in use.

Conclusion

Searching for a managed database solution? Choose Gcore Managed Database for PostgreSQL so you can focus on your core business while we manage your database.

  • 99.9% SLA for uninterrupted service with high-availability architecture
  • Adjustable database resources for changing demands
  • Currently in free public beta

Start managing your database

Related articles

TLS 1.3 vs TLS 1.2: what’s the difference?

TLS 1.3 vs 1.2 refers to the comparison between two versions of the Transport Layer Security protocol, a cryptographic standard that encrypts data exchanged between clients and servers to secure network communications. TLS 1.3, finalized in

What does SSL handshake failed mean?

An “SSL handshake failed” error occurs when a client and server can't complete the initial negotiation process required to establish a secure encrypted connection. This negotiation happens before any data transfer begins and typically compl

What is TLS 1.3?

TLS 1.3 is the latest version of the Transport Layer Security protocol, standardized in RFC 8446 in August 2018. This cryptographic protocol secures communication between clients and servers across the internet, from web browsing to API cal

What is DNS load balancing?

DNS load balancing is a technique that distributes incoming network traffic across multiple servers by manipulating DNS responses to improve the availability and performance of applications or services. It works at the application layer (la

What is an SSL handshake?

An SSL handshake, more accurately called a TLS handshake, is a process that establishes a secure encrypted connection between a client (like a web browser) and a server before any data transfer begins. As of 2024, over 95% of HTTPS websites

What is API Rate Limiting?

API rate limiting is the process of controlling how many requests a user or system can make to an API within a specific timeframe. This mechanism caps transactions to prevent server overload and ensures fair distribution of resources across

Subscribe to our newsletter

Get the latest industry trends, exclusive insights, and Gcore updates delivered straight to your inbox.