The error screen
Every blog owner has run into this error screen that, in its bare-bones form, really sends a chill down your spine. And if you’re reading this, it’s finally happened to you.
No WordPress link, no images or reassuring fonts. Just black letters on a white page.
And before you start panicking: no, your entire blog isn’t gone. Your images are still there, your themes, plugins, information, everything.
After you typed in your address, the connection went to fetch your website, only to not find it in the database. This error screen is its way of saying: I did my best, but I can’t find your blog.
Which leads to the second question…
Where is it, then?
To better understand where your website is, we should clear up one thing first:
WordPress uses PHP (a programming language) to communicate your commands to MySQL (WordPress database technology).
All of your site’s information is located in MySQL, from your theme layout to the font you use for it. As we mentioned, when you type in your website URL in the search bar, your entire page information is pulled from MySQL by using PHP.
So, when the error occurs, your website isn’t magically gone. It’s just that PHP commands have a difficult time locating and retrieving your website information. It is still in the database and simply needs to be brought back to the front.
Which means you can breathe easily.
As we go through the problems and fixes, you can turn to the table of contents for easier navigation:
Easy Fixes to “Error Establishing a Database Connection” in WordPress
What Causes a Connection Error
Manually Check Database Credentials
Manually Check Username and Password
Manually Reset Username and Password
Engage Your Visitors Indirectly
What causes a connection error
To know what needs fixing and how to properly troubleshoot, let’s go through some of the most common causes.
It’s a given that everyone will experience different causes of the error. Some of the most common ones we’ve seen involve:
- Incorrect login details that stem from typos, additional spaces, or wrong quotes;
- An unresponsive database server means that your hosting server is experiencing downtime, either due to heavier traffic or host issues.
- Corrupted WordPress files, including plugins, images, or links;
- A corrupted database and
- Low database memory, which stops your website from loading to its full capacity.
In the next section, we’ll explore a fix to each problem in a step-by-step guide.
Fixing the error
Find out Where the Connection Error is Occurring
To actually find out what caused the PHP command to fail, you’ll want to troubleshoot the error first.
The easiest way (especially for beginners) is to allow WordPress’s built-in database repair tool to dig around and try to fix whatever might be causing the issue. To enable this tool, follow the steps below:
- Log in to your cPanel(you can find the link in your host’s welcome email, or add:
- If your URL starts with HTTP – http://www.yourwebsite.com:2082
- If your URL starts with HTTP – https://www.yourwebsite.com:2083
- Once you’ve accessed cPanel, go to File Manager
- Find the WordPress installation folder
- Locate and open the wp-config.php file
- Add this line to the bottom of the page: define( ‘WP-ALLOW_REPAIR’, true );
Once you’re done, you should see the following screen:

You can repair the database, or repair and optimize it, although the second option will take a little while longer.
Once the troubleshooting and repair are done, you’ll see a report that looks like this:

If everything is okay, pay attention to the last few lines on the screen. This repair screen is actually accessible to anyone who visits your site, so long as you have that wp-allow_repair line in your wp-config file. As the instructions say, delete that line to prevent any unwanted tampering with your website.
If the repair tool hasn’t managed to fix your problem, then keep your wp-config file open for the next fix.
1. Login credentials
WordPress rarely, if ever, tampers with your username and password. It’s even rarer that they change on their own, without your direct influence.
However, both username and password can change or get corrupted if you’ve switched hosts recently, or played around with different plugins or themes.
What you need to do now is check if the wrong database credentials are causing the error.
If you have the wp-config.php file open, scroll down until you see this:

The ‘DB_NAME’, ‘DB_USER’, and others are the names for your website specifically. Then:
- Contact your host.
- Copy and paste these lines to them, and ask if they can verify your information.
- Once retrieved, replace the old credentials in wp-config with the ones from your provider.
- Re-upload the file and check if the error is gone.
In case you can’t reach your provider, or they don’t seem to be helpful, you can check the credentials manually.
1. Manually check database credentials
- Access your cPanel
- Find the Databases section
- Log in to phpMyAdmin
- On the left side, there will be a list, and your database name will be at the bottom:

- Compare this database name with the name in your wp-config.php file (‘DB_NAME’)
- If they match, then this isn’t the problem;
- If they don’t – update your wp-config.php file with the right name
Additionally, click the name of your database and select “options”. Check if the URL there matches your website URL. This could also prevent WordPress from fetching your website from the database.
If your database name and URL are perfectly fine, but you’re still getting the “error establishing a database connection” message, then you should manually check your username and password.
2. Manually check username and password
- Access your WordPress root directory
- Create a new PHP file
- Name it test.php or something similar
- Paste the following lines of code:
<?php
$test = mysql_connect(‘localhost’, ‘db_user’, ‘db_password’);
if (!$test) {
die(‘MySQL Error: ‘ . mysql_error());
}
echo ‘Database connection is working properly!’;
mysql_close($testConnection);
- Replace ‘DB_USER’ and ‘DB_PASSWORD’ above with credentials from your wp-config.php
- Access your website through the URL: https://yourwebsite.com/checkdb.php
- Then the problem lies in your password and username, and you’ll have to reset them.
3. Reset username and password
In just a few steps, you can solve the issue of a mismatched username and password.
- Access your cPanel
- Find the Databases section
- Click on MySQL Databases
- Click the Create User option
- Choose a new username and password
- Scroll below, and find Add User to Database
- Finally, use those same credentials to update your DB_USER and DB_PASSWORD in the wp-config.php file
Run a test check in the same way as you did in the previous section. If the problem was that your username and password did not match, then this should solve the issue.
If the error is still there, then your problem lies somewhere else down our list.
2. Unresponsive server
The reason why WordPress is having issues retrieving your website could be because of server downtime. Sometimes, when internet traffic is high, especially on popular pages, or the host is doing maintenance, the servers can be down.
To check this, you should first contact your host and ask if the problem is on their end.
If not, these kinds of issues resolve themselves after a little while. The server will automatically reboot, and your website will reappear.
That being said, a lot of the time, the downtime can last up to a few hours until the automatic reboot, which costs you precious visits. What you can do in this case is set up a so-called cron job.
Cron jobs are actually tasks that you schedule to be performed at certain times, automatically.
In this case, you can set up a cron job to check the state of your MySQL database server every hour:
- Log in to your cPanel
- Go to the Advanced section
- Click on Cron Jobs

- In the Command field, paste this command:
mysqlcheck –all-databases –check-only-changed –silent
- In other fields, you can check how often you want this command to be executed
- And that’s it!
With this command, Cron will check the status of the server, and you’ll know when and if it goes down again.
3. Corrupted WordPress files
There have been situations where site owners noticed that uploading the core WordPress files seems to solve the “error establishing a database connection”. This usually works because re-uploading the core files resets all file permissions and replaces any files that could’ve been corrupted.
Here’s how to try this fix:
- Download a new version of WordPress
- Unzip the folder
- Insidethe newly downloaded WordPress folder, delete the wp-config.php and the wp-content folder
NOTE: The above step is extremely important! If you don’t delete the newly unzipped wp-config and wp-content, they will overwrite all your old WordPress data, deleting all of your files, themes, and plugins located there!
- Open your FTP Client and upload the new WordPress files (WITHOUT THE TWO ABOVE)
- Test your connection!
If you’ve closely followed the steps above, then you should have a working website. Of course, if the problem was in the corrupted files.
Additional tip: For those a little more tech savvy, you can skip this whole process and simply delete your MySQL database, then import your backup one.
4. Corrupted WordPress database
A corrupted WordPress database can be easily solved by following the very first step on our list.
Running WordPress’s integrated database repair tool, you should be able to check this step off your list.
5. Low database memory
MySQL has trouble functioning when memory is too low, and it has a tendency to crash. More often than not, this can be the culprit behind your “Error establishing a database connection” message.
This memory issue happens if you recently implemented an add-on or an upgrade to your operating system. WordPress itself could’ve also changed the memory requirements for the website.
There are two options to fix this:
- Switch to a server with greater memory.
- Increase your PHP Memory Limit.
To increase your PHP memory limit, follow these steps:
- Access the WordPress root folder via FTP
- Open wp-config.php
- Paste the following just before the ending line: define( ‘WP_MEMORY_LIMIT’, ‘256M’ )
And voila! This should do the trick!
Additional tip: To prevent this from happening again in the future, look for a plugin that keeps track of your site’s processes. That way, you’ll be able to see which apps or features take up the most memory and react before the error occurs.
6. Switch browsers
Sometimes, the problem lies not in your WordPress website, but in the browser itself.
A lot of users reported that they would first check if the website loads in a different browser. For example, using Chrome or Safari, if the site won’t open in Firefox. If this works for you, too, the solution is simple.
Clear out the history and cache of the browser that doesn’t load your website. This should resolve the error.
What happens is that there was a database issue, but it resolved itself. However, the browser didn’t manage to update in time to mirror the fix.
7. Engage your visitors indirectly
Going way back to the beginning, the bare-bones error message on a white screen simply turns off not just you, but your website visitors.
It gives no information about what happened, how long your website will be down, or if you’re even working to fix the problem. All the visitors see is a broken link.
This can be resolved with some simple tampering in the code. You can create a custom page that gives enough information to make you look professional and on top of things.
What’s more, you can customize it so that the website notifies you via e-mail when visitors get the “error establishing a database connection”.
Want to find out how? Then follow these steps:
- Open Notepad
- Add <?php /* Template Name: db_error */ ?> at the top (name it however you want)
- Save the file under db-error.php.
- Connect via FTP Client
- Go to wp-contentfolderand upload the db-error.php to your themes subfolder
- Log in to your WordPress Admin area and create a new custom page
- Locate Page Attributes on the right side
- Choose db_error from the Template drop-down menu
- To choose how your page will look, you can use the following code template:
<?php ob_start();
header(‘HTTP/1.1 Service Temporarily Unavailable’);
header(‘Status: Service Temporarily Unavailable’);
header(‘Retry-After: 3600’); // 1 hour = 3600 seconds
mail(“email@example.com”, “Database Error”, “There’s a database problem!” . $_SERVER[‘REMOTE_ADDR’], “From: Sir Montgomery Scott”);
?><!DOCTYPE html>
<html lang=”en-US”>
<head>
<meta charset=”UTF-8″>
<title>Service Temporarily Unavailable</title>
</head>
<body>
<h1>Service Temporarily Unavailable</h1>
<p>The site is experiencing issues; we’re on it. Please try again later.<p>
<hr>
<address>Web Server at example.com</address>
</body>
</html>
Final advice
As WordPress users, we’ve grown accustomed to troubleshooting so many problems and bugs. Every now and then, we get an issue that we seemingly fix, only to be met with bugs in other places.
The most important thing to keep in mind is not to get overly frustrated. While it is taxing to spend hours searching for a solution, we’ve tried our best to find those that might work for you.
However, the internet is vast, and who knows how many fixes there are?
Found one that we didn’t include in the list? Let us know below!
FAQ
Why does WordPress show “Error Establishing a Database Connection”?
This error appears when PHP cannot connect to the MySQL database using the credentials defined in wp-config.php. It usually means incorrect DB_NAME, DB_USER, or DB_PASSWORD values, server downtime, corrupted files, or insufficient database memory.
How can I check if my WordPress database credentials are correct?
Open wp-config.php and verify DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. Then compare them with the database information inside cPanel and phpMyAdmin. If they don’t match exactly, update the credentials and re-upload the file.
Can hosting downtime cause a database connection error?
Yes, an unresponsive MySQL server or hosting downtime can prevent WordPress from retrieving website data. High traffic, maintenance, or server overload may temporarily block the database connection until the host restores service.
Does low PHP memory affect WordPress database connectivity?
Low PHP memory can cause MySQL to crash or stop responding, triggering the “Error Establishing a Database Connection” message. Increasing the WP_MEMORY_LIMIT in wp-config.php or upgrading your hosting plan can resolve memory-related database issues.
Is it safe to repair a corrupted WordPress database?
Yes, you can safely use WordPress’s built-in database repair tool by enabling WP_ALLOW_REPAIR in wp-config.php. After repairing and optimizing tables, remove the line to prevent public access to the repair page.