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

There are three ways to fix the 'MySQL Server Has Gone Away' error in WordPress.

  • Editing your WordPress wp-db.php File
  • Repairing your WordPress Database
  • Restoring your website using a Backup through your Hosting Provider

Editing your WordPress wp-db.php file

If your website's PHP timeout setting is low and your database is extensive, you will not be able to read the data required. You will get the 'MySQL Server Has Gone Away' error.

To fix this error, you need to edit the wp-db.php file of your WordPress application by implementing the steps listed below –

1. Log in to your cPanel account.

2. Go to the Files section and click the File Manager option.

3. Once you click on it, a new window (as shown below) will open.

Click on the public_html folder and select the website in which you are facing the issue.
    Here, we have selected as an example.

5. Select the wp-includes directory and double-click on it to open it.

6. Locate the 
wp-db.php file and open it with the default text editor.

7. Search the line (as shown below) in the wp-db.php file.

$this->ready = true;

8. Add the line (mentioned below) right below that code.

$this->query("set session wait_timeout=300");

It will set your PHP timeout value to 300 seconds which is enough to avoid any errors from showing up.

9. Go to the upper right side of the screen and click on the Save Changes button to save the file.

10. Now, clear the browser history & cache, and browse the website.

     You need to try the second solution if the issue is still there.

Repair the WordPress Database

Sometimes, your WordPress database can be corrupted, showing an error when you try to start the connection with it.

To fix it, you need to repair the database from the cPanel through the following steps –

1. Log in to the cPanel account.

2. Go to the Databases section and click on the MySQL Databases option.

3. The MySQL database window will open once you click on it.

4. Go to the Modify Databases section. 

5. In the Repair Database field, select the database of the WordPress site from the drop-down list and click on the Repair Database button to repair it.

Restore your Website using a Backup Through your Hosting Provider

If the above solutions do not fix your issue, you can restore your website from the available backup. 

You need to contact your hosting service provider for the latest available backup for your website. For AccuWeb Hosting Clients, we keep the last 15-day backup of the shared hosting account in our backup server. This can come in handy if our clients ever face such technical issues.

Was this answer helpful?

« Back