6 Ways to Fix the Database Connection Error in WordPress (2023)

You’re trying to access your website, which was running smoothly the last time you visited, but instead of the homepage, you’re faced with the WordPress error message “Error Establishing a Database Connection“.

The database connection error can cause goosebumps to the best of us but guess what? This error is entirely manageable and is one of the common WordPress errors. And I will show you how to fix the ‘error establishing a database connection’ in 6 different ways.

So, don’t sweat and keep reading.

Contents show

What is a WordPress Database?

Before you troubleshoot the database error, you should know what the heck the word database means and why it is so important. Well, WordPress utilizes the MySQL database for storing all information related to your website. This includes information about your login credentials, users, plugins, posts, and pages.

6 Ways to Fix the Database Connection Error in WordPress (1)

The media files and other uploads are not stored in the database but are stored in the wp-content folder separately.

WordPress retrieves all the information it needs from the MySQL server constantly. If there is an error in your database, WordPress will not be able to communicate with the MySQL server and will throw up a database connection error that we will troubleshoot below.

1. Check your database credentials

The most common reason why the database connection error occurs is due to wrong credentials in the wp-config.php file.

This file is located in your root WordPress installation. You can use either an FTP program like FileZilla or a file manager in your hosting panel to access your WordPress directory.

Next, navigate to the directory where WordPress installed. If you can see the folders wp-content, wp-includes, and wp-admin, you are in the right place.

Now scroll down to the wp-config.php file. Before tinkering with this file, you should backup all its contents.

So, open the file and copy all the contents of the file. Now create a text file with some name like wp-config.txt on your computer and paste the copied contents. Save the text file.

You can now return to editing the wp-config.php file.

(Video) Error establishing a database connection error in wordpress [SOLVED]

The wp-config.php file contains the details of your WordPress database. If there is any error here, it can throw up the database connection error.

6 Ways to Fix the Database Connection Error in WordPress (2)

There are 4 important things to verify here:

  1. Database name

Look for the line:

define('DB_Name', 'Name');

The ‘Name’ should match with your database name. To know your database name, you can either ask your hosting provider or you can access your MySQL database using your hosting panel.

Once you log in to the MySQL panel, you can see your database name on the left panel just below the information_schema.

6 Ways to Fix the Database Connection Error in WordPress (3)

Alternatively, you can click the Databases tab on the top to know your database name.

Ensure that the name matches the one in the wp-config file. If not, make the correction and save the file.

Related: WordPress Database Management and Optimization Guide

  1. Database username and password

The database username and password in wp-config.php should also tally with the actual username and password.

If you’re using cPanel then the database username will be listed under the Databases tab. If you’re using a custom panel like Dreamhost (which we are), then the database details like username and password will be listed under the Manage Database tab.


6 Ways to Fix the Database Connection Error in WordPress (4)

In case of any doubt, just ask your hosting provider for the database username and password.

Now, ensure that the username and password match with those in the following two entries in the wp-config.php file.

define('DB_USER', 'your_username');

define('DB_PASSWORD', 'your_password');

If they match, there’s nothing to do here. But if they don’t you should update the entries with the correct username and password.

(Video) How To Fix “Error Establishing A Database Connection” In WordPress

  1. Database hostname

Finally, check this line in the wp-config file:

define('DB_HOST', 'localhost');

This defines the MySQL (database) server location in the wp-config file. Most of the time, your database server will be the same as the one on which WordPress is installed. In this case, the hostname will correspond to ‘localhost’.

But if your database is located on a separate server, as in the case of Dreamhost, then the proper host location should be present like mysql.yoursite.com.

When in doubt, ask your hosting support for the correct database host entry.

2. Database connection error caused by plugins

In any type of WordPress error, a malfunctioning plugin or theme is the usual suspect.

To find out whether the error is caused by a plugin, log in to your web hosting panel and use the file manager to go to your WordPress directory. You can also use an FTP program like Filezilla for this if you don’t have access to a file manager.

In the WordPress directory, go to the wp-content folder. Within this, there is a ‘plugins’ folder. Rename this folder to any other name like plugins.hold or plugins-old.

6 Ways to Fix the Database Connection Error in WordPress (5)

This will deactivate all plugins on your website. Check your site; if the database connection error has disappeared, it means that one of the plugins was causing the error.

To identify the misconfigured plugin, log in to your website and go to the plugins dashboard. You will see an error message that ‘plugins have been disabled since the plugins folder does not exist’.

Don’t panic. Just restore the plugins folder to its original name i.e. ‘plugins’ in the wp-contents folder.

Next, head back to the plugins dashboard. You will see that all plugins are in a deactivated state. Now activate all plugins one by one.

If the database connection error recurs when you activate a plugin, means that the plugin was causing the error. You should deactivate the plugin to resolve the error.

However, if renaming the plugins folder did resolve the database connection error, you should follow the next step after restoring the name of the plugins folder in your WordPress installation.

3. Error connecting to database server

Sometimes, due to a sudden spike in website traffic, your database server is unable to handle the load, leading to a connection error. This situation is more likely to occur on shared hosting as compared to VPS or dedicated hosting.

In order to verify the connection between the database server and WordPress, you need to do the following.

  1. If you have another website hosted on the same server then simply visit that site. If it connects, it implies that the database connection is fine.
  2. If you have a single website, then first log in to phpMyAdmin and then connect to your database by selecting it. If the database tables show up, then the connection is OK.

If for any reason, the connection fails then you should your hosting support and ask them to resolve the error ASAP.

(Video) How to Fix "Error Establishing a Database Connection" Error in Wordpress [SOLVED]

4. Error in the database

If there is some error in the database, it could also cause the database connection error. In this case, you will need to repair your database. Fortunately, this is quite easy to accomplish.

Again, open the wp-config.php file for editing as described in step 1.

Then, add the following line of code after this line: define('DB_COLLATE', '');

define('WP_ALLOW_REPAIR', true);

What this code does is allows you to access the database repair options on your site. This option can be accessed by visiting the following link:


Here, you will see the following two options.

6 Ways to Fix the Database Connection Error in WordPress (6)

Click on the ‘Repair Database’ button to repair the database. Once you have done this, delete the code you added in the wp-config.php file.

Now check whether the ‘error connecting to WordPress database’ message has vanished. If it has, your problem is solved. Otherwise, move to the next solution.

Finding this solution required considerable effort and time. Consider rewarding me with a coffee!

5. Corrupted WordPress files

Sometimes, adding or deleting files can cause some core WordPress files to become corrupted. These files which are located in the wp-admin and wp-includes folders are vital for the smooth working of your website.

To rule out the possibility of corrupted files, you will need to replace the wp-admin and wp-includes folders in your WordPress installation.

Before, you proceed further I highly recommend that you take a full backup of your website using a free backup plugin like UpdraftPlus.

Now, you should download a fresh copy of WordPress from here.

(Video) Fix Error Establishing a Database Connection in WordPress

Next, unzip the files to your computer. In the unzipped files, you will see three folders: wp-admin, wp-includes, and wp-content. Delete the wp-content folder since we don’t need to upload it.

Next, upload the wp-admin and wp-includes folder to your WordPress installation using an FTP program like FileZilla.

You can also use your File Manager to upload the folders. When the ‘overwrite files’ message pops up, allow overwriting the existing files in these folders.

Once all the files have been replaced, visit your website. Hopefully, you will no longer see the database connection error message.

6. When everything fails

I have described five solutions to the WordPress database connection error. Hopefully, one of them worked for you.

In the unlikely event that none of the above methods clicked, you should contact your hosting support forthwith.

After all, every minute of downtime will cost your readers and possible revenue loss.

Describe your problem in detail and any plugin or theme that you might have installed before the error occurred. Managed web hosting companies like Cloudways have dedicated WordPress support and should resolve such errors easily.

You can also check out our reliable WordPress troubleshooting service to get expert help with this nagging problem.

Did you manage to fix the database connection error? If yes, which solution worked for you? Please let us know in the comments below.

Download the WordPress SEO eBook

Go from WordPress SEO Zero to Hero in no time. Also receive2 Bonus PDFswith this free eBook.

Take Action Now!

Give it a try. You will thank yourself later.

(Video) How to Fix Error Establishing a Database Connection


How do I fix error establishing a database connection in WordPress? ›

How to Fix “Error Establishing a Database Connection” in...
  1. Inspect the wp-config.php File of your WordPress website.
  2. Check if the Database User has the Correct Privileges.
  3. Repair the Database.
  4. Inspect the WordPress Site URL in the Database.
  5. Restore a Backup of the Site.
  6. Contact the Web Hosting Provider.

How do I fix database connection? ›

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.

How do I fix errors in WordPress? ›

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.

How do I fix localhost database errors in WordPress? ›

Reported by our users, these steps have helped some users resolve the database connection error on their websites.
  1. Update WordPress Site URL. Try updating the WordPress site URL using phpMyAdmin. ...
  2. Rebooting Web Server. ...
  3. Ask for help.
Jul 18, 2022

How do I check my WordPress database connection? ›

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 connect my database to my WordPress site? ›

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 you troubleshoot database errors? ›

Troubleshooting database issues
  1. Make sure that the server has the appropriate capacity to handle the load and is not shared with other systems.
  2. Check and make sure that the DB statistics are up to date.
  3. Check memory allocation to make sure that there are no unnecessary disk reads.

What is error establishing a database connection WordPress server? ›

Possibly the most common cause of the Error Establishing a Database Connection is simply that WordPress has incorrect login credentials for your database. This could be either the database name, username, or password. Remember, these login details are different from the ones you use to access your site.

What is a database connection error? ›

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.

What is the most common WordPress error? ›

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.

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 for errors in WordPress? ›

To review your error logs, navigate to your /wp-content/ folder in your File Manager. Locate the debug. log file. This file will contain all WordPress errors, warnings, and notices that were logged.

How do I clean up my WordPress database? ›

How to optimize your WordPress database
  1. Reduce the number of saved revisions. By default, WordPress saves revisions of your posts and pages. ...
  2. Prevent spam comments. ...
  3. Regularly empty your WordPress trash. ...
  4. Delete unused plugins and themes. ...
  5. Disable pingbacks and trackbacks. ...
  6. Delete unused media files.
Dec 7, 2022

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.

How do I reset my WordPress database? ›

Reset WordPress With A Plugin
  1. Install and activate the WP Reset plugin. ...
  2. Go to Tools > WP Reset.
  3. Scroll down to the Site Reset section.
  4. Type “'reset” in the Confirmation field.
  5. Click the Reset Site button.
  6. A popup message will appear asking you to confirm that you want to reset your site.
Dec 9, 2021

How do I update my WordPress database? ›

To update WordPress on your site using WP-CLI:
  1. Log into your server with the SSH credentials. ...
  2. Navigate to the root directory of your site. ...
  3. Next, update the WordPress version using the command wp core update . ...
  4. You will also need to update the database, for which the command is wp core update-db .

How do I connect my database to my website? ›

Table of Contents:
  1. Create the Virtual Machine.
  2. Install the MySQL Database.
  3. Prepare the MySQL Database.
  4. Replace the Static Website.
  5. Connect the Website to the Database.
  6. Select the Records in the Database.
  7. Insert a Record into the Database.
  8. Update a Record in the Database.
Dec 27, 2021

What is the default database for WordPress? ›

WordPress uses a database management system called MySQL, which is open source software. This means you'll sometimes hear your site's database referred to as a “MySQL database.” MySQL is what enables the database to store information and provide you with access to it.

What is the most common database error? ›

Redundancy. This is one of the most common database errors that developers struggle with, especially when they are forced to keep different versions of the same data updated.

How do you handle database failure? ›

Software and hardware failure
  1. The effects of database systems can be mitigated by keeping the computer hardware and software updated and practising the proper backup process.
  2. File corruption can be mitigated through use of the log files to restore the database. Some corrupt files can be repaired through DBMS software.
Jul 8, 2021

What are the common types of data errors? ›

Data can be affected by two types of error: sampling error and non-sampling error.

How do I fix WordPress connection is not secure? ›

The red padlock can happen if your websites has mixed content issues. You could either make sure that both URL values (WordPress Address and Site Address) at Settings > General include the HTTPS (not just HTTP), or install a mixed content/SSL plugin to do this for you.

What causes connection error? ›

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 are the top 3 things that slow a WordPress site down? ›

Here are 10 top reasons for a slow WordPress site:
  • Website has hidden malware. ...
  • Poor web host. ...
  • Running too many plugins. ...
  • Using poor-quality plugins and themes. ...
  • Not updating WordPress core, plugins, and themes. ...
  • Unnecessary JavaScript or long CSS. ...
  • Not optimizing images. ...
  • Not using caching plugins.
Oct 18, 2021

Is WordPress the most hacked CMS? ›

What's the most commonly-hacked CMS platform? WordPress was the most commonly-hacked CMS (content management system) in 2021, according to Sucuri's annual hacked website report. Over 95.6% of infections detected by Sucuri were on websites running WordPress.

How do I fix redirect problems in WordPress? ›

How To Fix The Redirect Loop Error In WordPress
  1. Check your URL settings.
  2. Clear your browser's cookies.
  3. Upgrade to a dedicated IP.
  4. Restore your . htaccess file.
  5. Disable your plugins.
Nov 1, 2019

How do you check for error correction? ›

How to Detect and Correct Errors? To detect and correct the errors, additional bits are added to the data bits at the time of transmission. The additional bits are called parity bits. They allow detection or correction of the errors.

What is error log in WordPress? ›

Your WordPress error log is a troubleshooting tool that can help you identify the plugins, themes, or code that are causing problems. You can then go ahead and find a fix for those WordPress errors.

Where is config file in WordPress? ›

One of the most important files in your WordPress installation is the wp-config. php file. This file is located in the root of your WordPress file directory and contains your website's base configuration details, such as database connection information.

How do I restore my WordPress site without a database? ›

To restore your website with Google's cache or Bing's cache, follow these steps:
  1. Search for your website or page on Google's or Bing's results page. ...
  2. Click on the arrow. ...
  3. Since we need a cached copy of your website, click on Cache option.
  4. Restore your website, pages or content, or whatever you need from this cached copy.
Sep 20, 2016

How to check database connection error in php? ›

Try this: <? php $servername = "localhost"; $database = "database"; $username = "user"; $password = "password"; // Create connection $conn = new mysqli($servername, $username, $password, $database); // Check connection if ($conn->connect_error) { die("Connection failed: " .

How do I restore a SQL database in WordPress? ›

Restore WordPress Database Backup with cPanel
  1. Log in to your cPanel account and under the “Files” section click on “Backup.” cPanel backup.
  2. Scroll down to “Restore a MySQL database backup.” Click on “Choose File” and select your *. sql file backup/export. Then click on “Upload.” cPanel restore MySQL database backup.
Sep 20, 2022

How do I manually optimize a WordPress database? ›

In order to manually optimize your WordPress site, you will first have to access PHPMyAdmin via your hosting provider. You will have to log in to cPanel, then open the PHPMyAdmin tool, and navigate to Databases. Then select the database you would like to optimize. Then select Check All to optimize all tables.

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 fill the database connection details in WordPress? ›

Update WordPress database connection details
  1. Step 1 - Open File Manager. Log into the one.com control panel. ...
  2. Step 2 - Open wp-config. php. ...
  3. Step 3 - Locate the login details. Usually, you can find the login details around line 20 in the wp-config file. ...
  4. Step 4 - Update details.

How do I fix err connection failed? ›

  1. Check If the Website Is Working. ...
  2. Disconnect from VPN. ...
  3. Reboot Your Network Device. ...
  4. Clear the Browser Cache. ...
  5. Deactivate Antivirus and Firewall. ...
  6. Disable Proxy Server Access. ...
  7. Reset TCP/IP Settings.

What causes most errors in a database *? ›

Incorrect data inputs are typically the most common error that may occur in data entry.

How do I manually update my WordPress database? ›

Manually upgrade WordPress using SSH
  1. Navigate to the root directory of your WordPress site. ...
  2. Next, check for WordPress core updates. ...
  3. Update WP version by typing in wp core update . ...
  4. In case you need to update the database as well, you can run the following command: wp core update-db .
  5. And that's it!
Jul 20, 2022

Why is my MySQL database not connecting? ›

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.


1. Fix Error establishing a database connection in WordPress | Also Repair & Optimize Database | 2022
(Hey, Let's Learn Something)
2. How to Fix "Error Establishing Database Connection" in WordPress
3. 5 Fixes: Error Establishing a Database Connection in WordPress
4. How To Fix The “Error Establishing a Database Connection” in WordPress
5. How to debug and fix AWS bitnami wordpress error ‘Error establishing a database connection’ ?
(Jitendra Kasaudhan)
6. Error Establishing a Database Connection for WordPress
(AOS Note)
Top Articles
Latest Posts
Article information

Author: Tish Haag

Last Updated: 02/26/2023

Views: 6159

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Tish Haag

Birthday: 1999-11-18

Address: 30256 Tara Expressway, Kutchburgh, VT 92892-0078

Phone: +4215847628708

Job: Internal Consulting Engineer

Hobby: Roller skating, Roller skating, Kayaking, Flying, Graffiti, Ghost hunting, scrapbook

Introduction: My name is Tish Haag, I am a excited, delightful, curious, beautiful, agreeable, enchanting, fancy person who loves writing and wants to share my knowledge and understanding with you.