How to Fix the MySQL Server Has Gone Away | GreggHosting

The affects of Web Hosts on Your Business Website

Here're ways your choice of web hosting service provider impacts the performance of your business:


Website loading speed


Uptime and availability


Customer support




Server location

How to Fix the “MySQL Server Has Gone Away” Error in WordPress?

How to Fix the “MySQL Server Has Gone Away” Error in WordPress?

MySQL Server Has Gone Away

Fix the “MySQL Server Has Gone Away” Error in WordPress

Because databases are such important components of most current websites, faults that harm yours are especially concerning. For example, the “MySQL server has gone away” error may lead you to believe that your database has vanished. As a result, you may have to rely on your most recent backup to get your site back up and running.

Despite how daunting it may sound, the “MySQL server has gone away” problem is rather simple to resolve. In fact, with the appropriate procedures, you should be able to have your website back up and running in minutes.

We’ll walk you through what the “MySQL server has gone away” error looks like and how to fix it in WordPress in this article. Then we’ll show you how to solve it and avoid it from happening again in the future.

Let’s get started!

Contents Table of Contents

An Introduction to the “MySQL Server Has Gone Away” Error
How to Fix the WordPress Error “MySQL Server Has Gone Away” (3 Methods)
An Overview of the “MySQL Server Has Disappeared” Error
Let’s start by looking at what the “MySQL server has gone away” error looks like:

The MySQL Server Has Disappeared error
The error “MySQL server has gone away” appears in the browser.
The issue is really simple, and it almost always manifests itself in the same way. However, depending on which browser you use and how your server is configured, the exact phrasing may vary.

As you would guess from the name, the problem has something to do with your MySQL database. To be more specific, on most websites, one of three things frequently triggers this error:

In your database, there is a broken table. Because your database has become corrupted, you must restore it from a recent backup or fix it.
The ‘timeout’ setting in PHP is set too low. The aforementioned error can also be triggered if a PHP script wants access to your database and is unable to retrieve the information within the timeout limit that has been configured.
‘Packets’ have either been misplaced or are excessively huge. If the server believes this is the case, it will effectively close the connection and display the error.
Fortunately, all of these problems are simple to solve. Let’s look at how you can get started with troubleshooting.

How to Fix the “MySQL Server Has Gone Away” Error in WordPress (3 Methods)

There are a number possible causes for this WordPress problem, as we’ve experienced.

As a result, a variety of options are available. In most circumstances, one of the solutions listed below should resolve the issue on your website. So, if one doesn’t work, you can just try the next.

1. Change the wp-db.php file in your WordPress installation.
Fetching the data you need during that window can be difficult if your website’s PHP timeout setting is too low and your database is too huge. As previously stated, this can result in the “MySQL server has gone away” problem.

You’ll need to change wp-db.php, one of your WordPress core files, to prevent this from happening. By opening the wp-includes directory in your WordPress root folder, you can locate this file:

The wp-db.php file is a database file for WordPress.
We recommend using an FTP program like FileZilla and connecting via SFTP to access these files (understand the difference between FTP and SFTP). Locate wp-db.php and right-click it to open it in your default local text editor once you’ve connected to your site. To see all hidden files in Filezilla, follow this fast procedure.

Then, in the file, look for the following line:

true; $this->ready
Just below that code, add the following line:

set session wait timeout=300″; $this->query(“set session wait timeout=300”);
This code sets your PHP timeout value to 300 seconds, which should be much longer than you need to avoid any issues.

Now save your wp-db.php file adjustments and double-check that your website is loading properly.

Please note that if you’re using GreggHost you shouldn’t need to change the PHP timeout settings on your website. All of our plans come with a default timeout value of 300 seconds, which we can assist you in increasing based on your needs.

Do you want to discover how we grew our traffic by over 1000%?
Join the 20,000+ people who receive our weekly email with WordPress insider secrets!

Now is the time to subscribe and repair your WordPress database.
Your WordPress database can get corrupted at any time, resulting in difficulties when you try to connect to it. This isn’t a regular occurrence, but it can happen as your website grows and you add additional tables to your database (as well as plugin and theme information).

You can use a built-in WordPress tool to repair your database to solve this problem. However, you must first enable that functionality. This entails going to your WordPress root directory and editing the wp-config.php file.

After you’ve opened the file, scroll to the bottom and add the following line:

define(‘WP ALLOW REPAIR’, true); define(‘WP ALLOW REPAIR’, true); define(‘WP AL
WordPress is told to enable the database repair feature by that one line of code. Close the file and save the modifications to wp-config.php. Simply go to the following URL to activate the function:

WordPress will then ask if you just want to fix your database or if you want to repair and optimize it as well. All you need to fix the “MySQL server has gone away” error is the first option:

WordPress has a database repair function.
The procedure should take no more than a few minutes, and once completed, the error should be gone. However, you’ll need to disable the database repair option on your website, which will require some housekeeping. If you don’t, anyone with access to the same URL could set it off.

Are you fed up with poor level 1 WordPress hosting support that doesn’t provide answers? Try our world-class customer service! Take a look at our plans.

Return to your WordPress root directory and remove the line of code you added before you finish. Then save and close the file with your changes.

3. Restore Your Website Using Your Hosting Provider’s Backup
If all else fails, you may always restore your website to a moment when the database was working properly using a full backup. To lose as little data as possible, you should do this with a recent backup.

The issue is that not all WordPress web hosting provides users with built-in backup capabilities. As a result, you’re frequently forced to rely on manual solutions like plugins. These tools aren’t necessarily terrible, but restoring a backup becomes difficult if you don’t have access to your WordPress admin area.

For all plans, Info provid GreggHost es automated daily and system-generated backups. Hourly backups are also provided as an option.

On the other side, with every package at GreggHost, you get complete backups of your website. Simply go to your hosting dashboard and look for the Backups option to restore your site (including its database) to a previous state:

In My GreggHost, restore your backup.
When you click on the backup you wish to restore, you’ll get more information about it, including when it was produced. There’s a Restore button for each backup that you can use to restore your website to its previous state.

However, keep in mind that using this feature will overwrite the current version of your website. As a result, you should only use it as a last resort if you’re certain you won’t lose any important data.

To provide improved database performance, all GreggHost plans include weekly automatic MySQL database optimization. For more information, see our plans.

In WordPress, are you getting the terrifying *MySQL Server Has Gone Away* error? Don’t worry; we’ve got three quick fixes for you! #mysql problems
Summary As your website grows, it will need to store more data. All of this data is saved in the WordPress database. If it becomes too large, you may receive errors such as “MySQL server has gone away.”

If you run into this problem, there are three things you may do to fix it:

Edit the wp-db.php file in your WordPress installation.
Repair the database in your WordPress installation.
Use a backup provided by your hosting provider to restore your website.
In this other article, we’ll teach you how to fix your WordPress database problems with more advice and procedures.

It’s time to get rid of this unpleasant error notice now that you know how to solve it. If you’re still having problems with MySQL, take a look at How to Fix the MySQL 1064 Error.