The “error establishing a database connection” is probably one of the most common errors WordPress users can encounter. It’s closely tied to the white screen of death(WSOD). This error means your website is no longer communicating or has access to your WordPress database; thus, your entire website goes down.
You should resolve this error immediately, as this can directly affect your sales, traffic, and analytics.
But don’t worry, today we’ll discuss some common scenarios that cause this error and some easy ways to get your site back up and running in no time.
Check Out Our Video Guide to Fixing The “Error Establishing a Database Connection”
What Is The “Error Establishing a Database Connection”?
All the information on your WordPress site, such as post data, page data, meta information, plugin settings, login information, etc. is stored in your MySQL database. The only data not stored there is media content such as images and your theme/plugin/core files such as index.php, wp-login.php, etc.
When someone visits your website, PHP executes the code on the page, queries the information from the database, and then displays it to the visitor in their browser.
If this isn’t working correctly, you are left with the “error establishing a database connection” message, as seen below. The entire page is blank because no data can be retrieved to render the page, as the connection is not working properly. Not only does this break the frontend of your site, but it will also prevent you from accessing your WordPress dashboard.

However, visitors might not see this error on the frontend right away. That is because your site is most likely still serving from cache until it expires. For example, at Kinsta, all WordPress sites are cached for one hour by default. Therefore, if a site is still serving from the cache, it might appear acceptable to a visitor.
At Kinsta, our support team can increase the duration of your cache to, say, an hour or even a week if you want. If you have a site that doesn’t change very often, this can increase your site’s performance as it does not have to grab new files as often after the cache expires. And in cases like the above, the frontend of the site in most cases (unless you have a script or part of your site breaking the cache) would stay up a lot longer.
When visitors try to access your site while this error is happening, it will generate a 500 HTTP status code in your logs. This same status code appears with an “internal server error.” It means that something went wrong on the server, and the requested resource was not delivered. When everything is working properly, your site will generate a 200 HTTP status code, which means everything is fine.

If you’re a Kinsta client, you could also look at the 500 error breakdown report in MyKinsta analytics to see if it’s something that has been a reoccurring problem.

What Are the Most Common Causes of This Error?
So why exactly does this happen? Well, here are a few common reasons below. And don’t worry, we will go into each of these more in-depth so you can know how to fix them. Typically you can resolve this error in under 15 minutes.
- The most common issue is that your database login credentials are incorrect. Your WordPress site uses separate login information to connect to its MySQL database.
- Your database is corrupted. With so many moving parts with themes, plugins, and users constantly deleting and installing them, sometimes databases get corrupted. This can be due to a missing or individually corrupted table, or perhaps some information was deleted by accident.
- You may have corrupt files in your WordPress installation. This can even happen sometimes due to hackers.
- Issues with your database server. Several things could be wrong on the web host’s end, such as overloading the database from a traffic spike or being unresponsive from too many concurrent connections. This is common with shared hosts as they utilize the same resources for many users on the same servers.
- A spike in traffic. Depending on the web host you use, your server might be unable to handle many concurrent database connections. An increase in traffic can lead to temporary problems with the database.
How To Fix The “Error Establishing a Database Connection”?
Before troubleshooting the error, we recommend taking a WordPress site backup. Many of the recommendations below involve manipulating information in your database, so you don’t want to make things worse. You should always backup before trying to fix things on your WordPress site, no matter how tech-savvy you think you are.
You can use a popular WordPress backup plugin such as VaultPress or WP Time Capsule to backup your files and database.
If you are a Kinsta user, you can take advantage of our one-click backup feature. Click into your WordPress site in MyKinsta, click on “Backups” and then on “Back up now.”

You then also have the option to restore a backup to production or staging. Or you can manually backup your MySQL database using phpMyAdmin. Once you have a successful backup, it is time to troubleshootyour database connection issues.
1. Check Your Database Login Credentials
The first thing to do is check to ensure your database login credentials are correct. This is by far the most common reason why the “error establishing a database connection” message occurs. Especially right after people migrate to a new hosting provider. The connection details for your WordPress site are stored in the wp-config.php file, which is generally located at the root of your WordPress site.
It contains four important pieces of information that must be correct for the connection to occur successfully.
Database Name
// ** MySQL settings ** ///** The name of the database for WordPress */define('DB_NAME', 'xxxxxx');
MySQL database username
/** MySQL database username */define('DB_USER', 'xxxxxx');
MySQL database password
/** MySQL database password */define('DB_PASSWORD', 'xxxxxxxxx');
MySQL hostname (server)
/** MySQL hostname */define('DB_HOST', 'localhost');
To access your wp-config.php file, you can connect to your site via SFTP and browse to the root of your site. Or, if you are using cPanel, you can click on “File Manager,” browse to the root of your site, and right-click to edit the file.
cPanel file manager
Here is an example below of what the file looks like when opened.

You need to now check your current values against those on your server to ensure they are correct. Follow the directions below for cPanel and Kinsta users.
Check Database Credentials in cPanel
The first thing to check is the database name. To do this, you must log in to phpMyAdmin in cPanelunder the Databases section.

You should see your database name at the bottom on the left. You can ignore the “information_schema” database as this is something used by the host. You will then want to compare that name against the DB_NAME value in your wp-config.php file. If they match, then this isn’t the problem. If they don’t match, you need to update your wp-config.php file.

You can also verify this is the correct database by ensuring it contains your WordPress site’s URL. To do this, click on the database and then click into the wp_options table (this might be slightly different for security purposes, such as wpxx_options). At the top of the table, you will see values for your site’s URL and name. If these match your current site, you can rest assured you are in the right place.

If your database name was already correct and you still get the “error establishing a database connection” message, you will also want to check your username and password. To do this, you will need to create a new PHP file in the root directory of your WordPress site and input the following code. You can name it whatever you want, such as checkdb.php. Change the values of db_user and db_password with those in your wp-config.php file.
<?php$test = mysqli_connect('localhost', 'db_user', 'db_password');if (!$test) {die('MySQL Error: ' . mysqli_error());}echo 'Database connection is working properly!';mysqli_close($testConnection);
Then browse the file on your WordPress site: https://yourdomain.com/checkdb.php. If you get a “MySQL Error: Access denied,” then you know your username or password is wrong, and you will need to continue to the next step to reset your credentials.

Below is the message you want to see, “Database connection is working properly.” But of course, if it were, then you wouldn’t be here. Be sure to delete/remove this file after you are done testing.

So next, you need to reset your username and password. In cPanel, click on MySQL Databases under the Databases section.

Scroll down and create a new MySQL user. Try and pick a unique username and password so they can’t easily be guessed. The password generator tool they provide works excellent. Then click on “Create User.” Alternatively, you could change the password on this screen for the current database user.

Then scroll down and add your new user to your database. The next screen will ask which privileges you want to assign. Select “All Privileges.”

Then take those new credentials and update your wp-config.php file. You will want to update the DB_USER and DB_PASSWORD values. You could also rerun the test file from earlier. This should then resolve your credentials issue. If not, you could still have the wrong hostname (DB_HOST). Some hosts use different values.
See a list of some common DB host values. Typically this will be localhost. But you can always reach out to your hosting provider or check their documentation if you aren’t sure. Some might also use 127.0.0.1 instead of localhost.
If you have followed everything above and are still receiving the “error establishing a database connection” message, proceed to the following troubleshooting steps below.
Check Database Credentials With Kinsta
If you are a Kinsta user, checking your credentials against your wp-config.php file and the server is much easier! All you need to do is click on the info section of your site, and towards the bottom, you will see the database name, username, and password. By default, Kinsta uses localhost for the DB_HOST.

Then take those new credentials and update your wp-config.php file. You will want to update the DB_USER and DB_PASSWORD values. This should then resolve your credentials issue. If you need to reset these credentials, contact our support team. If you have followed everything above and are still receiving the “error establishing a database connection” message, proceed to the following troubleshooting steps below.
2. Repair Corrupt WordPress Database
In some cases, it could be that your database has become corrupt. This can occasionally happen (although not very often) as, over time, hundreds of tables are constantly added/removed by new plugins and themes. If you try to login to your WordPress site’s dashboard and are receiving the following error, it means your database is corrupt: “One or more database tables are unavailable. The database may need to be repaired.” It is important to note that you might only see this error on the back-end, whereas you see the “error establishing a database connection” message on the frontend.
WordPress has a database repair mode that you can initiate. Add the following to the bottom of your wp-config.php file.
define('WP_ALLOW_REPAIR', true);

Then browse to the following location on your WordPress site: https://yourdomain.com/wp-admin/maint/repair.php. You will then have the option to repair the database or repair and optimize the database. Since you are probably troubleshooting an outage on your site now, we recommend using the repair database option as it is quicker.

After running the repair of the database above, ensure that you remove the line of code you added to your wp-config.php file. Otherwise, anyone will be able to access the repair.php page. If you are running cPanel, you can also run a repair from within the MySQL databases screen.

Or you could run a repair from within phpMyAdmin. Simply log in to phpMyAdmin, click on your database, and select all the tables. Then from the dropdown, click on “Repair table.” This is essentially just running the REPAIR TABLEcommand.

And finally, your other option would be to run the repair using WP-CLIwith the following command:
wp db repair
See more documentation on usage in the WordPress developer resources.
If you want to optimize your database, we have some great tutorials on how to optimize WordPress revisionsfor performance, along with how to convert your MyISAM tables to InnoDB. If you still have issues on your site, proceed to the next troubleshooting step.
Suggested reading: How to Fix the “MySQL Server Has Gone Away” Error in WordPress.
3. Fix Corrupt WordPress Files
The following possible reason you might see the “error establishing a database connection” message is that your WordPress core files have become corrupt. Whether this originated from an issue with transferring files via FTP, a hacker gaining access to your site, or a problem with your host, you can quickly fix this. However, we recommend taking a backup of your site before trying this.
You are going to replace the core version of WordPress on your site. You aren’t touching your plugins, themes, or media, just the WordPress installation itself.
However, you may lose any changes or custom code you’ve added to files such as .htaccess or wp-config.php. If you backed up your website before troubleshooting, you’d have copies of those files that you can restore later.
To get started, you must download a fresh WordPress copyfrom WordPress.org.

Unzip this file on your computer. Inside, you will want to delete the wp-content folder and the wp-config-sample.php file.

Then upload the remaining files via SFTP to your site, overwriting your existing files. This will replace all the problematic files and ensure you have fresh ones that are clean and not corrupted. It is recommended to clear your browser cacheafter doing this. Then check your WordPress site to see if the error still exists.
4. Check for Issues With Your Database Server
If nothing above has helped resolve your issue, we highly recommend checking with your hosting provider as it could be an issue with your database server. For example, if there are too many concurrent connections to your database at once, it could generate an error. This is because many hosts limit their servers on how many connections are allowed at once. Utilizing a caching plugin can help minimize the database interactions on your site. If you are a Kinsta client, you don’t need caching plugins, as we have fast server-level caching.
This problem can happen a lot on shared hosts, as someone else could theoretically be affecting your site. This is because shared hosts utilize all the same resources on servers. This is another reason we recommend using a high-performance managed WordPress host, so things aren’t overcrowded. It also means the environment is typically fine-tuned to handle large amounts of traffic, specifically to WordPress sites.
The knowledgeable Kinsta support team is always a click away on the bottom right side of the dashboard and available 24/7 if you need help. And don’t forget we have representatives to assist you in multiple languages, including English, Spanish, French, Italian, and Portuguese.

5. Restore Latest Backup
And last but not least, you can always resort to a backup if needed. In some cases, this might be a faster way to resolve the issue if you aren’t worried about losing any data between when your last backup was taken. Many hosts have their own backup restore process. Remember that you might need to restore both your database and your files.
If you are a Kinsta user, you can quickly restore a backup of your site within the Backups section of your site. Choose the time you want to revert and click on “Restore to.” You can then select whether you want to restore to Staging or your Live site.

You will then be prompted to confirm the restoration. Enter your site name and click on “OK.” It also creates a backup at the restoration time so you can undo the restoration if needed.

Summary
As you can see, there are quite a few ways to fix the “error establishing a database connection” in WordPress. The most common being invalid credentials in the wp-config.php file. Checking to ensure those are correct is the best place to start. The last thing you want for a website is to experience downtime.
Hopefully, one of the steps above helped you get your site back up and running. Remember, you can always restore your site from a backup if needed.
Have you experienced the “error establishing a database connection” message on your site? If so, were you able to resolve it? Let us know below in the comments.
Get all your applications, databases and WordPress sites online and under one roof. Our feature-packed, high-performance cloud platform includes:
- Easy setup and management in the MyKinsta dashboard
- 24/7 expert support
- The best Google Cloud Platform hardware and network, powered by Kubernetes for maximum scalability
- An enterprise-level Cloudflare integration for speed and security
- Global audience reach with up to 35 data centers and 275 PoPs worldwide
Get started with a free trial of our Application Hosting or Database Hosting. Explore our plans or talk to sales to find your best fit.
FAQs
How do I fix error establishing database connection in WordPress Godaddy? ›
WordPress uses connection strings to know which database to connect to. When your site is not connected to your database, it displays the Error establishing a database connection notification. To resolve this error, update the connection strings on your WordPress site.
What does it mean when it says error establishing a database connection? ›This error means that your website files (on the webserver) are not able to connect to your database (on the database server). This article lists some common reasons this error could display on your site, including: Incorrect database credentials in your config file. The hostname isn't working.
How do I get rid of error establishing a database connection? ›- Inspect the wp-config.php File of your WordPress website.
- Check if the Database User has the Correct Privileges.
- Repair the Database.
- Inspect the WordPress Site URL in the Database.
- Restore a Backup of the Site.
- Contact the Web Hosting Provider.
- Configure firewalls to work with SQL Server. ...
- Test connections to SQL Server by using Universal Data Link (UDL) files. ...
- Use PortQryUI tool with SQL Server. ...
- Check whether SQL Server is listening on dynamic or static ports.
PhpMyAdmin also allows you to easily import your WordPress database. Simply launch phpMyAdmin and then select your WordPress database. Next, you need to click on the 'Import' link from the top menu. On the next screen, click on the Choose file button and then select your database backup file you downloaded earlier.
How do I reset my WordPress database? ›- Install and activate the WP Reset plugin. ...
- Go to Tools > WP Reset.
- Scroll down to the Site Reset section.
- Type “'reset” in the Confirmation field.
- Click the Reset Site button.
- A popup message will appear asking you to confirm that you want to reset your site.
Click on the Hosting on the top menu and then cPanel on the submenu. Find the Files section and click on File Manager. You may get a popup asking you to select the directory you want to start in. Choose the Document Root for option and select the website you want to get the database information for.
How do I resolve a WordPress error? ›Getting started with WordPress error troubleshooting
You can start by clearing your cache. A cache helps your browsers load sites faster by storing data. Clearing it helps you get rid of outdated content, which may be enough to fix your issue. You should also consider updating your theme, plugins, and WordPress core.
Manually Fixing Mixed Content Errors in WordPress
First, you need to go to Settings » General and make sure that the 'WordPress Address' and 'Site Address' options have HTTPS URLs. If you see URLs starting with 'http', then you need to go ahead and change them to 'https'.
Here are some reasons the Can't connect to local MySQL server error might occur: mysqld is not running on the local host. Check your operating system's process list to ensure the mysqld process is present. You're running a MySQL server on Windows with many TCP/IP connections to it.
How do I get rid of a connection error? ›
- Reload the page. ...
- Consider if you're using public Wi-Fi. ...
- Check your computer's date and time. ...
- Go incognito. ...
- Clear Your browsing data. ...
- Check your antivirus software. ...
- Update your operating system. ...
- Restart your computer.
- Click the Connections tab .
- Click New connection and choose Database from the menu. The New connection window appears.
- Choose the database type you want to connect to. ...
- Provide the connection properties for your database. ...
- Click Add.
The error "Error establishing a database connection" might occur for the following reasons: There are corrupted database tables. The remote database connection is disabled. The database service is down.
What is the database name in WordPress? ›WordPress uses a database management system called MySQL, which is open source software.
What is error establishing a database connection WordPress HostGator? ›Database Connection Error
If you get an error message that states, “Error establishing a database connection,” then this means that your site has experienced an issue when it tried to make a connection to the WordPress database. When you're experiencing this error, it could have to do with your wp-config. php file.
To test the connection to your database, run the telnet hostname port on your Looker server. For example, if you are running MySQL on the default port and your database name is mydb, the command would be telnet mydb 3306 . If the connection is working, you will see something similar to this: Trying 10.10.
What are the causes of database failure? ›There are many reasons that can cause database failures such as network failure, system crash, natural disasters, carelessness, sabotage(corrupting the data intentionally), software errors, etc.
How do I find database connection settings? ›...
This information includes the:
- Database Host.
- Database Port.
- Database Name.
- Database User.
- Database Password.
- Database Version.
- Database Storage Engine.
Error establishing a database connection This either means that the username and password information in your wp-config. php file is incorrect or we can't contact the database server at localhost:3306. This could mean your host's database server is down.
How do I connect my database to my website? ›- Create the Virtual Machine.
- Install the MySQL Database.
- Prepare the MySQL Database.
- Replace the Static Website.
- Connect the Website to the Database.
- Select the Records in the Database.
- Insert a Record into the Database.
- Update a Record in the Database.
How do I restore my WordPress site without a database? ›
- Search for your website or page on Google's or Bing's results page. ...
- Click on the arrow. ...
- Since we need a cached copy of your website, click on Cache option.
- Restore your website, pages or content, or whatever you need from this cached copy.
- Navigate to the root directory of your WordPress site. ...
- Next, check for WordPress core updates. ...
- Update WP version by typing in wp core update . ...
- In case you need to update the database as well, you can run the following command: wp core update-db .
- And that's it!
- Step 1 - Open File Manager. Log into the one.com control panel. ...
- Step 2 - Open wp-config. php. ...
- Step 3 - Locate the login details. Usually, you can find the login details around line 20 in the wp-config file. ...
- Step 4 - Update details.
If you are experiencing problems displaying WordPress.com pages, clearing the browser cache is a good first step to try to resolve the issue. Some situations where you can find it very useful to clear your browser cache: When the page or post editor is not loading or it fails to load.
What is a common issue with WordPress? ›The WordPress internal server error is often the most common WordPress issue and the most confusing too. This error message typically shows up when something is wrong, but the server doesn't know where the problem is.
How do I check my WordPress site issues? ›Just log in to the hosting dashboard, then go to Sites > Tools > WordPress debugging and click Enable. You can then look around your site to find the cause of the issue or check the log.
How do I get rid of SSL certificate error? ›- Adjust your local time and date settings (check the Google Chrome section above for instructions).
- Clear your browser's cache and cookies.
- Clear your OS's SSL slate or delete any local certificates for Gmail.
- Diagnose the problem with an online tool.
- Install an intermediate certificate on your web server.
- Generate a new Certificate Signing Request.
- Upgrade to a dedicated IP address.
- Get a wildcard SSL certificate.
- Change all URLS to HTTPS.
- Renew your SSL certificate.
...
Here's how to do it:
- Generate a new CSR.
- Activate your SSL certificate.
- Validate your SSL renewal.
- Install and renew your SSL certificate.
- Create Database.
- Create a Folder in htdocs.
- Create Database Connection File In PHP.
- Create new php file to check your database connection.
- Run it.
How do I establish a connection in MySQL? ›
- In the Server name box, enter the MySQL server name. In the Server port box, enter the port number to be 3306. It is the default port.
- In the User name box, enter a MySQL account that has the necessary permissions.
- In the Password box, enter the password for the specified user name.
- Locate the MySQL Command-Line Client. ...
- Run the client. ...
- Enter your password. ...
- Get a list of databases. ...
- Create a database. ...
- Select the database you want to use. ...
- Create a table and insert data. ...
- Finish working with the MySQL Command-Line Client.
Summary. If you run into the “ERR_CONNECTION_RESET” error, it means that your browser can't establish a connection to the remote server. In most cases, it's due to a misconfiguration in your internet settings or something else that's blocking the connection.
What can cause the error message your connection is not secure? ›This error is caused by an issue with the website's SSL certificate – it's missing, or it's expired, or it wasn't issued by a legitimate certificate authority, or the client can't access it for some other reason. SSL certificates are necessary for serving websites over secure HTTPS connections.
Do you need MySQL for WordPress? ›MySQL uses Structured Query Language (SQL), a popular language for databases. MySQL works best with other open-source applications like WordPress, Apache web server, the Linux operating system and PHP. Before you can install the WordPress software, you first need to have a MySQL database.
How do I update my WordPress database in MySQL? ›- Step 1: Create a new 5. ...
- Step 2: Create a dump of your old database. ...
- Step 3: Import the old database content into the new database. ...
- Step 3b: I'm getting a SQL error! ...
- Step 4: Setting up WordPress to talk to the new database. ...
- Step 5: Upgrade WordPress through FTP. ...
- Step 6: Logging in for the first time.
WordPress uses MySQL as its management system. MySQL uses the Structured Query Language to create, read, update, and delete data from a database. While most MySQL queries run automatically, users can also perform them manually to change WordPress URLs and carry out other tasks.
How do I make my database active? ›Database administrators can use the ACTIVATE DATABASE command to start the selected databases. This eliminates any application time spent on database initialization. The ACTIVATE DATABASE command is the only way to explicitly activate a database.
How to connect database to server? ›Connect to a SQL Server instance
Start SQL Server Management Studio. The first time you run SSMS, the Connect to Server window opens. If it doesn't open, you can open it manually by selecting Object Explorer > Connect > Database Engine. For Server type, select Database Engine (usually the default option).
Database connection files
When you create the connection in the Catalog tree, the file is created in \\<computer_name>\Users\<user_name>\AppData\Roaming\ESRI\Desktop<release#>\ArcCatalog, but you can move the connection file to another location.
Why is my WordPress not installing? ›
The major causes of installation problems are: incorrect editing of the wp-config file database details. uploading WordPress to the wrong location on your server. using a web server that doesn't support standard WordPress hosting requirements.
How do I fix error establishing a database connection on WordPress on Digitalocean? ›- Why Does WordPress Database Error Occur?
- Determine Error Establishing a Database Connection.
- Check Database Login Credentials in wp-config.
- Reset Username and Password.
- Database Host Value.
There are 4 main types of errors on WordPress: HTTP, PHP, MySQL and JavaScript errors. These errors can be due to an incompatibility between plugins, a corrupted file, a server or memory problem, etc. Some of the famous errors include the 500 error, White Screen of Death and database connection error.
How do I resolve a WordPress issue? ›- Research Your Error Message. ...
- Create a Complete Backup of Your WordPress Site. ...
- Clear Browser Cache. ...
- Clear Your WordPress Cache. ...
- Deactivate All Plugins Installed on Your Website. ...
- Switch to a Default WordPress Theme. ...
- Refresh Permalinks.
First, you need to launch the phpMyAdmin from your hosting account's cPanel dashboard. After that, you need to select your WordPress database. PhpMyAdmin will show your WordPress database tables. You need to click on the 'Browse' link next to wp_users table.
How do I fill the database connection details in WordPress? ›- Step 1 - Open File Manager. Log into the one.com control panel. ...
- Step 2 - Open wp-config. php. ...
- Step 3 - Locate the login details. Usually, you can find the login details around line 20 in the wp-config file. ...
- Step 4 - Update details.
You can confirm this information from your WordPress hosting account dashboard. Simply log in to your hosting account and click on MySQL databases under the database section.
How do I restore my WordPress database? ›To get started, open your WordPress dashboard and select Settings > UpdraftPlus Backups from the menu. Then, under the Backup / Restore tab, scroll down to Existing Backups. Here you will find the most recent backups of your website. Select the backup you would like to use, and then click on the Restore button.
How do I manually clean my WordPress database? ›- Reduce the number of saved revisions. By default, WordPress saves revisions of your posts and pages. ...
- Prevent spam comments. ...
- Regularly empty your WordPress trash. ...
- Delete unused plugins and themes. ...
- Disable pingbacks and trackbacks. ...
- Delete unused media files.