6 Ways to Fix "MySQL Server Has Gone Away" in WordPress

The 'MySQL server has gone away' error in WordPress is almost never caused by what most site owners assume: a corrupt database. Nine times out of ten, the issue is a timeout, a memory limit, or a connection-dropping configuration — not a database that's literally vanished. Once you understand that, the fix becomes a matter of tuning a handful of server and WordPress settings rather than restoring from a backup.

This error typically surfaces during large uploads, backup imports, or plugin updates. The MySQL server hasn't actually gone anywhere — it just stopped waiting for a query that took too long to complete. Here's how to bring it back and keep it stable.

Before you start: back up your site and database

Before making any changes to your server or WordPress configuration, create a full backup. Use a plugin like UpdraftPlus or your hosting control panel's backup tool. Export your database via phpMyAdmin or a WordPress plugin. A single misconfigured line in wp-config.php can take your site offline, so a backup is non-negotiable.

If you're unsure how to access your server's files, you'll need FTP credentials or your hosting cPanel login. Most fixes below require editing either wp-config.php or your server's PHP configuration file (php.ini).

Common causes of the 'MySQL server has gone away' error

6 ways to fix the 'MySQL server has gone away' error

1. Increase the MySQL wait timeout

The most common reason for this error is that MySQL closes a connection after a period of inactivity — usually 30 seconds on shared hosts. When WordPress tries to run a query after that window, it finds the connection gone.

Log into your hosting cPanel and open phpMyAdmin. Click on the 'Variables' tab and search for ‘waittimeout'.

define('WPMYSQLWAITTIMEOUT', 60);

After saving, test by re-running the action that triggered the error. If the error persists, increase the timeout to 120 or 300 on larger sites with heavy import tasks.

2. Raise the maxallowedpacket size

When you upload a large media file, import a WXR XML file, or restore a database backup, MySQL discards any packet larger than its maxallowedpacket setting. The default on many servers is just 16 MB.

In phpMyAdmin, navigate to the 'Variables' tab and search for ‘maxallowedpacket' . Increase the value to 128 MB or 256 MB. If you cannot edit MySQL variables, add this line to wp-config.php:

define('WPMYSQLMAXALLOWEDPACKET', 128  1024  1024);

On managed WordPress hosts like WP Engine or Kinsta, open a support ticket and ask them to increase maxallowedpacket. They often allow up to 256 MB upon request.

3. Add reconnect support to wp-config.php

WordPress can automatically attempt to reconnect to MySQL when a connection drops. This feature is disabled by default on most installations. Add the following line to your wp-config.php file just above the line that says 'That's all, stop editing':

define('WPMYSQLSETRECONNECT', true);

This tells WordPress's internal MySQL wrapper to attempt a reconnection up to one time before throwing an error. It won't solve all timeout issues, but it catches many transient drops caused by brief MySQL restarts or network blips.

4. Increase PHP memory limit

If PHP runs out of memory while processing a large query, the connection to MySQL can appear to be lost. This is especially common during plugin updates, theme imports, or when using page builders with heavy media libraries.

Edit your wp-config.php file and add this line:

define('WPMEMORYLIMIT', '256M');

If your hosting uses a php.ini file, also increase the PHP memory limit there:

memorylimit = 256M

After making the change, retry the action that caused the error. If the problem was memory-related, the error should disappear.

5. Switch to persistent MySQL connections (advanced)

WordPress normally opens a fresh MySQL connection for each page load. On busy sites, this can exhaust the connection pool, leading to dropped connections for long-running processes.

Add this line to wp-config.php:

define('WPMYSQLUSEPERSISTENTCONNECTIONS', true);

Persistent connections reuse existing connections instead of opening new ones. This reduces the chance of hitting MySQL's maxconnections limit. Use this only if you understand the implications: persistent connections can cause deadlocks on some shared hosts or with poorly coded plugins. Test thoroughly before deploying to production.

6. Check and increase MySQL maxconnections

A less common but real cause: your MySQL server has reached its maximum number of simultaneous connections. When WordPress tries to open a new one, the connection is refused — and the error message may be 'gone away'.

In phpMyAdmin, go to the 'Variables' tab and look for ‘maxconnections'. On shared hosting, this is often capped at 10-20 connections. If you see frequent connection spikes (check your hosting control panel's logs), consider raising the limit.

A quick comparison of common hosting limits can help you decide the root cause:

SettingTypical shared host limitRecommended for WordPress
waittimeout30 seconds60-300 seconds
maxallowedpacket16 MB128-256 MB
maxconnections10-2050-100
PHP memory limit64 MB128-256 MB

How to prevent the 'MySQL server has gone away' error

Prevention often comes down to monitoring your hosting environment and keeping your site lean. Use a caching plugin like W3 Total Cache or WP Rocket to reduce the number of database queries per page load. Schedule large imports or backups during off-peak hours. Avoid running multiple database-heavy plugins simultaneously — for example, don't run a full-site backup while also importing a WXR file.

Consider upgrading from shared hosting to a managed WordPress host or a low-end VPS if you routinely hit resource limits. The few extra dollars per month are cheaper than lost traffic and frustrated visitors.

Frequently asked questions

Does the 'MySQL server has gone away' error mean my database is corrupt?

No. In nearly all cases, the error signals a timeout, memory limit, or packet-size restriction — not database corruption. Run a repair from phpMyAdmin or use a plugin like WP-DBManager to rule out corruption, but focus on the server settings listed above.

Can I fix this error without access to wp-config.php?

If you cannot edit wp-config.php via FTP or your hosting file manager, contact your hosting provider. Most can adjust MySQL variables (waittimeout, maxallowedpacket) from the server side. Some managed hosts also offer a UI for PHP memory limits in their control panel.

Will increasing MySQL timeout affect site performance?

Raising waittimeout from 30 to 300 seconds will not slow down normal browsing. It only keeps idle connections open longer. The downside is that a server with thousands of idle connections may exhaust memory, but on a typical WordPress site with a few dozen active users, the impact is negligible.

What if none of these fixes work?

If you've tried all six methods and the error persists, contact your hosting provider. Ask them to check the MySQL error log and confirm whether the MySQL service is restarting unexpectedly. On some shared hosts, MySQL restarts daily during maintenance windows, killing all open connections.

Should I use a plugin to fix this?

Several WordPress plugins claim to fix database connection errors, but most simply add the wp-config.php constants mentioned above. You're better off making the changes manually so you understand what each setting does. If you prefer a plugin, 'WP Health' or 'Heartbeat Control' can help manage some related settings, but they won't replace server-level fixes.

Get back to publishing — without breaking your database

Once your site is running smoothly again, the last thing you want is another disruption. Tools like nativeWP can help you automate your content workflow so you spend less time wrestling with server errors and more time producing pages that actually rank. With nativeWP, you bulk-generate SEO-optimized articles using your own OpenRouter API key and schedule them directly to WordPress — no more manual uploads that trigger timeouts.

If you need to keep a consistent publishing cadence without pushing your MySQL server to its limits, check out nativeWP.