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

What is health check monitoring and how does it improve system reliability?

Health check monitoring is a systematic process that tracks the availability and performance of your servers, applications, and infrastructure by sending automated requests at regular intervals. Most systems run checks every 30 to 60 second

What is GSLB and why is it important for global applications?

GSLB (Global Server Load Balancing) is a load balancing service that distributes client requests across multiple geographically dispersed data centers to improve performance, availability, and compliance.At its core, GSLB works at the DNS l

How do load balancing algorithms work?

Load balancing automatically distributes incoming network traffic across multiple compute resources according to specified rules. Modern applications can generate millions of requests per second, and sharing the load boosts performance and

Serverless vs containers: which execution model should you choose?

Serverless vs containersBuilding modern applications means making a fundamental choice: serverless or containers?This decision affects how you use code, manage resources, and pay for infrastructure. Here's what you need to know.Serverless c

What Is an Origin Server?

An origin server is a computer or service that stores and delivers original content to end-users, serving as the primary source for websites and web applications. When a user requests content, the origin server processes the request and sen

What is DNS TTL and how does it work?

A Domain Name System Time to Live (DNS TTL) is a timer measured in seconds, that determines how long a DNS record stays cached before resolvers must refresh it from the authoritative nameserver.DNS TTL controls caching behavior across the g

Subscribe to our newsletter

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