Fix “Error Establishing A Database Connection” in WordPress – step by step guide
If your WordPress site suddenly shows the dreaded “Error Establishing a Database Connection,” it means the application has lost access to the MySQL database. This error halts your entire site, including admin access, and can directly impact traffic, revenue, and trust. This guide explains what causes this issue and outlines how developers, site admins, and business owners can fix it fast, with minimal downtime.
Preliminary checks
When you face the “Error Establishing a Database Connection” error, you have to identify recent changes that have been made to the website, and follow the checklist
- Has your hosting been changed recently?
- Have you performed any recent WordPress core updates?
- Have you updated any themes or plugins recently?
- Have you installed a new plugin or changed your site’s theme?
What causes the “Error Establishing a Database Connection” error?
It’s usually something that can be fixed pretty easily. Here are a few of the most common reasons it might be happening:
- Incorrect database configuration
- Incorrect table prefix
- Database corruption issues
- The database server is offline
- High traffic overload
- Corrupted WordPress installation files
5 proven fixes for “Error Establishing a Database Connection” error in WordPress
Let’s walk through the most reliable fixes. We’ll start with the most common culprit: misconfigured database credentials in your WordPress setup.

Check your database configuration
Using incorrect credentials is the most frequent reason for the “Error Establishing a Database Connection” error. The database configuration details are stored under wp-config.php
file under the root directory of your WordPress installation.
You’ll need to find the following lines within the wp-config.php
file:
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** Database username */
define( 'DB_USER', 'username_here' );
/** Database password */
define( 'DB_PASSWORD', 'password_here' );
/** Database hostname */
define( 'DB_HOST', 'localhost' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
Head over to your WordPress hosting settings and double-check that the database name, username, password, and host are all correct. Each host puts this info in a different spot. E.g., on Nexcess, you’ll find it under the site’s Database menu. Once you update and save the wp-config.php
file with the correct details, refresh your site and see if it’s working again.

Tip: If you have command line access, you can check the database connection process by running wp db check
after you have made changes to the wp-config.php
file.
Verify the table prefix
Now that you’ve fixed the database misconfiguration, the “Error Establishing a Database Connection” issue has been resolved. However, your site still isn’t functioning properly, the content isn’t loading, and you’re unable to log in. This issue often occurs when the table prefix in your configuration is incorrect. Find the table prefix in the wp-config.php
/**
* WordPress database table prefix.
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
* At the installation time, database tables are created with the specified prefix.
* Changing this value after WordPress is installed will make your site think
* it has not been installed.
* @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/#table-prefix
*/
$table_prefix = 'wp_';
The default table prefix in WordPress is wp_
, but it might be different for your site. To find the correct prefix, log in to phpMyAdmin and open your website’s database. As shown in the image below, the table prefix in this example is xyz_

Repair the corrupted database
After following steps 1 and 2, if you are still facing the issue, it could be that your database has been corrupted. When your database is corrupted, you will see an error like “One or more database tables are unavailable. The database may need to be repaired.” While this error is different from the “Error Establishing a Database Connection” error, it still needs to be fixed for the site to continue properly. This error may only be displayed on the admin side of the WordPress site.
WordPress has a database repair mode that you can use. Add the following line in the wp-config.php
file, just above the line where ABSPATH
is defined.
define('WP_ALLOW_REPAIR', true);
/* Add any custom values between this line and the "stop editing" line. */
define('WP_ALLOW_REPAIR', true);
/* That's all, stop editing! Happy publishing. */
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
Once you’ve completed the changes, navigate to http://www.yoursite.com/wp-admin/maint/repair.php
to access the repair page (be sure to replace yoursite.com
with your actual domain). Then, simply click on Repair Database to begin the repair process.

After the database repair is complete, make sure to remove the code you added to the wp-config.php
file. If you leave it there, anyone could potentially access the repair page and start the process.
Tip: If you have command line access, you can initiate the database repair process by running wp db repair
without needing to add the code mentioned above.
Upgrade the server resources
You might see the “Error Establishing a Database Connection” when your WordPress website gets a lot of traffic, but your database server is not capable of handling the same amount.
Too many visitors at once can slow down your site or even make it go offline. You’ll notice signs like pages loading slowly, database errors, or your site running out of memory.
To fix this, you can upgrade your server’s CPU, RAM, storage, and bandwidth so it can handle more traffic and bigger tasks. If your hosting plan is too small for your needs, think about moving to a bigger option like a VPS or a dedicated server. It’s a good idea to keep an eye on your site’s performance so you know when it’s time to upgrade before problems get worse.
If you want a hosting solution that automatically adjusts resources based on traffic, you can check out WordPress VIP, which offers powerful hosting with enterprise-grade security and scalability. For SME users, you can use Presseable.

Inspect for corrupted files
Another possible reason for the “Error Establishing a Database Connection” message is that your WordPress core files may be corrupted. Before starting the step, make sure to take a backup of your website. You are going to replace the WP core files. To get started, download a fresh WordPress copy from WordPress

Unzip the downloaded file and delete the wp-content
folder. Then, upload the remaining files through SFTP or your host’s File Manager, ensuring you replace the old files. This will update the core WordPress files, keeping them clean and intact. Afterward, clear your browser cache and check if the issue is gone.

Contact hosting support
If you’ve tried all the steps above and the issue is still not fixed, it’s a good idea to contact your hosting provider’s support team. Most hosting companies can guide you through the troubleshooting process, and in some cases, they might even fix the problem for you.
Importance of prompt resolution
When your website displays an “Error Establishing a Database Connection,” it becomes completely inaccessible to visitors, which can cause:
- Loss of revenue for e-commerce sites and businesses that depend on online sales
- Frustrated visitors who may lose confidence in your brand
- Negative effects on your search engine rankings
- Damage to your business reputation as users question your site’s reliability
Quick resolution of this error is essential to maintain site availability, protect your income stream, and preserve customer trust.
Preventive measures
Once your site is back up, the next step is ensuring it doesn’t happen again. These preventive practices will help you reduce the risk of future database connection errors and recover quickly if they do occur.
Regular backups
You should back up your website regularly. If your hosting provider offers automated backups, use them. Otherwise, install a WordPress plugin like UpdraftPlus to create backups automatically.
Monitoring solutions
You need to monitor your website’s performance. Set up UptimeRobot to check if your site is working from different locations around the world. You can also use New Relic or similar APM tools to track your application’s performance and identify any code problems.
Security best practices
You must follow security best practices. Keep all your WordPress plugins, themes, and core files updated. Only use plugins and themes from trusted sources and avoid nulled versions that might contain malware. Choose a host that offers staging functionality so you can test updates before applying them to your live site. Run WPScan regularly to find and fix security issues.
Good hosting
You should select a quality hosting provider. For small to medium businesses, consider Pressable’s managed WordPress hosting. For enterprise needs, look at WordPress VIP. These providers include helpful services like regular backups, security testing, and uptime monitoring.
Content Delivery Network (CDN)
You can reduce the load on your website by using a Content Delivery Network (CDN) like Cloudflare. A CDN also helps protect your site from DDoS attacks and bots. It makes your website faster by loading files like images, styles, scripts, and videos from the closest CDN server instead of your main server.
Final thoughts on “Error Establishing Database Connection” error
This guide walks you through 5 solutions to help fix the issue. While resolving it can be straightforward, identifying the exact cause might take some time. By carefully following the steps, you can get your website back online and running smoothly.
To sum it up: choose a reliable hosting provider, keep an eye on your website’s uptime, and regularly check the security of your plugins and themes. Always use themes and plugins from trusted sources, and don’t hesitate to reach out to your hosting support or a WordPress expert if you need help.
On this page
Leave a Reply