Choose another country or region to see content specific to your location and shop online.
USA

How to Fix the WordPress error ‘Error Establishing a Database Connection’

Picture of William Bacchus
William Bacchus

Published: April 9, 2024

Last updated: April 12, 2024

Table of Contents

How to fix the 'Error Establishing a Database Connection' WordPress error (1)

If you’re a WordPress user, you’ve likely encountered the ‘Error Establishing a Database Connection’ WordPress error at some point. This issue can be quite troublesome, especially for beginners. It essentially renders your site inaccessible to users, which can be disastrous for businesses reliant on their online presence.

This comprehensive guide will walk you through the process of resolving this WordPress error step by step. But first, let’s understand what causes this issue.

Understanding the ‘Error Establishing a Database Connection’ WordPress error

A database is a software that stores, organizes, and retrieves data for other applications. WordPress, being a content management system, relies heavily on its database to store all your content and other website data. Whenever a user visits your site, WordPress connects to its database to fetch the necessary information.

To connect to the database, WordPress requires the following information:

  • Your database name
  • Database username and password
  • Database server

This information is stored in your WordPress configuration file, known as wp-config.php. If any of these details are incorrect, WordPress will fail to connect to your database server, leading to the dreaded ‘Error establishing a database connection’ WordPress error.

This error is pretty common and can be caused by several factors. Apart from incorrect credentials, this WordPress error can also occur if the database server is down, or the database files are corrupt.

How to Fix the Database Connection WordPress error

Let’s dive into the step-by-step process of troubleshooting and resolving this WordPress error.

1. Verify Your WordPress Database Credentials

The most common reason for the database connection WordPress error is incorrect credentials. If you’ve recently migrated your WordPress site to a new host, this could be the culprit.

The wp-config.php file stores your WordPress database credentials. It’s a crucial configuration file containing important settings, including database information. It looks a little something like this:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

You need to ensure that the database name, username, password, and database host details are correct. You can confirm this information from your WordPress hosting account dashboard.

We are going to use The Elite Web Co., as our example in this case. However, the steps will be fairly similar for other hosts (the options might just be named slightly differently).

  1. Log in to your dashboard.
  2. Navigate to the hosting product you wish to view the database information of by finding that product and selecting manage.
  3. In the hosting dashboard, select settings.
  1. Under the production site tab, click View on your database details and you will be able to view your database name, username, password, and database host details.

Once you’ve confirmed all your database details, you can modify this information in your wp-config.php file if necessary.

After making these changes, try visiting your website again to check if the database connection WordPress error has been resolved. If the error persists, it indicates that a different issue is at play. Let’s continue.

2. Double-check Your Database Host Information

If you’re certain that your database name, username, and password information are correct, you might want to verify your database host information. Although most WordPress hosting companies use ‘localhost’ as your database host, some managed WordPress hosting companies use separate servers to host databases. In such cases, your database host information won’t be ‘localhost’, and you’ll need to contact your WordPress hosting company to confirm these details.

For customers of The Elite Web Co., you can find a contact number in your country here.

3. Repair Your WordPress Database

If you encounter a different WordPress error in the wp-admin dashboard, such as ‘One or more database tables are unavailable’ or ‘The database may need to be repaired’, you need to repair your database.

WordPress allows you to do this by adding a specific line of code in your wp-config.php file. Copy and paste the below:

define('WP_ALLOW_REPAIR', true);

Once you’ve added this line of code, you can access the settings by visiting this specific URL:

http://www.yoursite.com/wp-admin/maint/repair.php

Alternatively, you can repair your database from your hosting account’s control panel.

4. Check If Your Database Server Is Down

If all the above checks don’t resolve the issue, it’s possible that your database server (MySQL server) might be down. This can happen due to excessive traffic on a server. In such cases, you should contact your hosting provider and inquire about the responsiveness of your MySQL server.

Additional Solutions

If none of the above solutions work, here are some additional steps that you can try:

1. Update the WordPress Site URL

You can update the WordPress site URL using phpMyAdmin in your hosting control panel. To begin, navigate to phpMyAdmin within your hosting account dashboard and choose your WordPress database from the provided list. Next, switch to the SQL menu located at the top and input the following MySQL query:

UPDATE wp_options SET option_value='YOUR_SITE_URL' WHERE option_name='siteurl'

2. Rebooting Web Server

If you are using a dedicated server, local server, or a virtual private server (VPS), try rebooting your servers.

3. Check out this information

For further ways to resolve your database connection WordPress error, check out this article which details more troubleshooting tips.

4. Reach out for help

If all else fails, you might need to contact your web hosting company. They can help troubleshoot the problem, guide you in the right direction, or even fix it for you.

Customers of The Elite Web Co., will be pleased to know that they are cared for by an award-winning customer support team. Unlike other web hosting companies, Elite customers never have to worry about waiting on hold for ages and not getting anywhere, or being transferred back and forth between departments. Available 24/7, any issues you have establishing a database connection in WordPress won’t last for long.

Conclusion

By following these steps, you should be able to fix the ‘Error establishing a database connection’ issue in your WordPress site. Remember, the key is to remain patient and systematically approach the problem. Good luck!

Sign up for free news, tips & offers

Your email is safe with us, we don't spam.

Picture of William Bacchus
William Bacchus
Will joined the Elite team in 2021. He has a background in content writing as well as a keen interest in media journalism. His interests include taijutsu and a immense passion for film and television. He aims to inform as many people as he possibly can about the vast and often confusing nature of web design!

Leave a Reply

Your email address will not be published. Required fields are marked *

Reseller login

If you’re a reseller, use the button below to sign in. (your reseller account is separate to your regular account)

New customer

New to ELITEWEB.Co? Create an account to get started today.

Registered users

Have an account? Sign in now.

Sign up to our newsletter for the latest news + a Free WordPress Guide

NEWSLETTER