What is "error establishing a database connection" and how to fix it 

Encountering an 'Error Establishing a Database Connection'? Learn the causes, troubleshooting steps, and solutions to fix this common issue, ensuring seamless access to your database and uninterrupted website functionality. Get expert tips and guidance here.

Updated: 29 Jun, 23 by Susith Nonis 10 Min

List of content you will read in this article:

The error "Error Establishing a Database Connection" is frequently seen on WordPress. This error occurs When the website fails to connect to the WordPress database.

Your WordPress website's post, page, meta, plugin settings, login, and other data are all stored in your MySQL database. The only data types not saved are images and your theme/plugin/core files like index.php, wp-login.php, etc.

When a user visits a website, PHP executes the page's code, requests a database, and displays the results in the user's browser.

You are left with the notice "problem establishing a database connection" if this isn't working correctly. A failed connection prevents data from being gathered to render the website, leaving the page blank.

To fix an error establishing a database connection, you must find its cause. Here are some of the common causes of this error:

  • Your database login information is not correct. Your WordPress website connects to its MySQL database using different login credentials.
  • Your database has been tainted. Databases can become damaged because there are many moving elements, including themes and plugins, and users continuously delete and install them. This might result from a table being absent, individually corrupted, or accidental data deletion.
  • Your WordPress installation has corrupt files. Even hackers have the potential to do this occasionally.
  • Your database server has problems. There could be several issues on the web host's end, including a traffic spike overflowing the database or excessive concurrent connections, making it unavailable. This is typical as shared hosts use the same resources for numerous users on the same servers.
  • An increase in traffic. Your server might be unable to manage numerous concurrent database connections, depending on your web host. A spike in traffic may be among the causes of errors in establishing a database connection.

The most popular strategies to eliminate the "Error Establishing a Database Connection" error are listed below. 

Make sure to back up your website before you attempt to fix the mistake. You can use it to restore your website if something goes wrong.

Check to see if your domain points to your host provider

When you change hosting companies, your files will be transferred automatically to the new host. However, database failure will result if your domain is not pointing to the host where the database is stored.

The wp-config.php file, typically found at the root of your WordPress site, contains the connection information for your WordPress site. The link to the work contains four critical pieces of information that must be accurate.

If the results are different, you have to change the nameservers at your domain registrar to fix the error establishing a database connection. Get a list of the nameservers from your hosting dashboard, and then enter them into the control panel of your domain registrar.

You can also use the A record to point to your domain name. A particular kind of DNS record links your domain to the appropriate IP address. Remember that the A record only directs traffic to static IP addresses.

Check your database server.

MySQL server being down is also one of the common causes of errors in establishing a database connection. There is a limit on how many clients can be connected to a database server simultaneously.

It could be unable to manage more connections when it exceeds that limit. For this reason, we advise contacting your web host to have your MySQL server checked.

You can check to see whether your MySQL server is down on other websites that are hosted on the same server as your own. If you only host one website, you can use PHP to connect to MySQL and see if the WordPress database user has the right permissions.

Access your public html folder from your hosting management panel. There, make a new PHP file with whatever name you like.

Then, enter the following code:


$link = mysqli_connect('localhost', 'username', 'password');

if (!$link) {

die('Could not connect: ' . mysqli_error());


echo 'Connected successfully';



Your credentials should be used in place of the username and database password. Finally, upload this file to your website so visitors can access it.

If it connects successfully, it signifies that your user has the necessary rights and the "Error Establishing a Database Connection" warning is being caused by something else.

Check the database login credentials.

Invalid login credentials are the main cause of the "Error Establishing a Database Connection" error. This typically occurs following a WordPress site migration to a different hosting company.

To solve this issue, check whether the database login settings match those in your wp-config.php file. You can access this file using an FTP program or the WordPress File Manager in your hosting control panel.

Change the database host information in the wp-config.php file if your database username and password are right but you're still getting the error notice. 

Web hosting companies frequently utilize localhost as the database host when running WordPress. We advise contacting your web hosting provider to confirm your database host information.

🌳🌳Unlock the power of scalability and performance with Monovm VPS hosting, providing you with blazing-fast speeds, dedicated resources, and unparalleled control for your online ventures.🌳🌳

Fix the corrupted files.

Corrupted files are also among the causes of errors in establishing a database connection. One of the causes of file corruption is a broken theme or plugin. Checking each one separately will help you determine which element is the problem. 

If the error manifests after activating a new theme, your theme may be the cause.

Go to Appearance -> Themes on your WordPress dashboard to change themes to fix this issue.

If you still can’t fix the error in establishing a database connection by changing the theme, the issue's root can be a corrupted plugin. To identify the offender in this situation, try disabling all your plugins and re-enabling them one at a time.

An alternative is to rename the relevant folder from your hosting control panel to disable all WordPress plugins. Themes and plugins should not be disabled simultaneously, though, as this would make it much more difficult to identify the source of the issue.

If the error goes away when you rename the plugins folder, one of the plugins is the problem. Rename the plugin's folder to its original name once you have reclaimed access to your website's back end. 

This will make all of the WordPress plugins inactive, but you can activate them again one at a time from the admin area.

Create a new database.

Your database may be completely corrupted and no longer functional if all the abovementioned techniques fail to fix errors establishing a database connection.

In this situation, you must use your hosting control panel to establish a new MySQL database and user. Restore your website backup to ensure you don't lose any crucial website data after creating a new MySQL database.

WordPress website URL update

You might need to alter your WordPress URLs if you recently switched web hosting. Navigate to phpMyAdmin from your hosting dashboard to accomplish this. Access your WordPress database after that and select the SQL tab.

The following code should be copied and pasted into the field:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.old-domain.com','http://www.new-domain.com');

Change "http://www.old-domain.com" and "http://www.new-domain.com" to the appropriate URLs for your new and old websites. When finished, press the Go button.

Restart the website server, then restore the backup

Rebooting a server is an option for users of virtual private servers, dedicated servers, and local servers. Your web and database server will restart, which might fix some issues. A root account and SSH clients like Bitvise or Putty can accomplish this.

Sometimes, you might have to restore your database and WordPress files from a backup. Find out if your web server performs automatic backups, then download the most recent copy of your website.

Databases which use the MySQL database management system provide the foundation of WordPress websites. The necessary database entries are requested by PHP commands when website visitors browse your WordPress blog. 

This request for database information has failed if the user sees the "Error establishing a database connection" notice. Sadly, this error message does not explain why WordPress could not connect to the database.

The most common causes of errors establishing a database connection are incorrectly stored login information for the database or a corrupted database. This can result from a plugin that modifies files without your knowledge or consent. 

The database server itself may be another cause of the issue. Finding the precise source of the mistake is, therefore, the first step you have to take to fix the error by establishing a database connection. 

People also read: 

Susith Nonis

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.

user monovm

Yesenia Morissette PhD

2024, Jun, 24

This post is incredibly comprehensive and insightful! Understanding the reasons behind the "Error Establishing a Database Connection" and having clear steps to resolve it can be a real lifesaver for anyone managing a WordPress site. The troubleshooting tips, like checking database login credentials, fixing corrupted files, and even creating a new database, are practical and clearly explained. Thanks for making such detailed resources available!