Tuesday, July 1, 2025

How to Resolve WordPress Error Establishing Database Connection

Error Establishing a Database Connection indicates a critical error in WordPress which renders your website not reachable for users. It happens in WordPress when the database connection cannot be established.

Since there are multiple factors affecting this connection, this error can be a little difficult for beginners to troubleshoot.

We have been running our blog on WordPress for the last 14 years and during this time we have faced many errors and warnings, one of which is “Error Establishing a Database Connection”. Through our experience and many times of trial and error, we have learned how such issues can be resolved without disrupting the site.

Want to stay ahead with AI-driven WordPress insights and stay updated with the latest trends? Subscribe for daily search insights at wpguidepro.com to improve your WordPress strategy!

What Causes the Error Establishing a Database Connection in WordPress?

A database stores and organizes various information, making it simple to recover data using software programs. WordPress is a content management system (CMS), and like all other CMSs, it makes use of a database to store all your website information and data. WordPress then connects to the database every time a user visits your site.

WordPress needs the following information to connect to the database:

  • Your (Example: wpguidepro_db) database name
  • Database username and password
  • Database server

The file that stores data is WordPress configuration file as wp-config.php.

If any of such information is wrong, WordPress would be unable to connect to the database server, and an error Error establishing a database connection will be displayed.

Check Your WordPress Database Credentials

The primary cause of the Error establishing a database connection issue is incorrect credentials.

This is almost certainly the very first problem you’ll encounter if you have moved your WordPress site to a new host recently. WordPress keeps your database login details in a specific file called wp-config.php. This particular configuration file contains a list of all critical databases that requires to be configured for WordPress

If you have never edited wp-config.php, check out our beginner’s guide where we explain step-by-step safely edit this file.

You will find lines like these in the wp-config.php file:

/** 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' );

How to Check Database Info from Hosting Panel (Bluehost Example):

Database username and passsowrd

Login to hosting account. Open “Website” tab from left sidebar, then switch to “Advanced” tab. Scroll down till you find “Database” section. Click on Manage button which is next to Database.

After checking everything for the database, you may edit the details in wp-config.php if needed. Then check your website again to confirm if the error regarding database connection is still there. If the error still exists, then something else must be the cause.

Check Your Database Host Information

In the case that you are absolutely certain your database name, username, and password details are correct, at this point in time you need to make sure that your database host information is also accurate.

Most WordPress (WP) hosting companies keep your database host on localhost. some managed WordPress hosting companies host their databases on separate servers. In such a case, your database host will not be localhost.

This means that you will need to contact your WordPress hosting company to confirm these details.

Repair WordPress Database

In the wp-admin dashboard, you might notice other issues such as, ‘A database table is missing’ or ‘The database might need repair.’ In this particular scenario, you will need to repair your database.

All you need to do is insert a single line in your wp-config.php file. Remember to put it before the line ‘That’s all, stop editing!

define('WP_ALLOW_REPAIR', true);

After this, you can access the settings from the following link:

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

Make sure to change yoursite.com to your domain name.

You will view the ‘Repair Database’ button which commences the process.

“Note: Users do not need to be logged in to access the database repair page. Don’t forget to remove this line from the wp-config.php file once you are done optimizing your database.”

If you don’t want to add code on your site, through the hosting account’s cPanel interface, you can repair it as well.

Log on to your hosting account, then head over to the ‘Websites’ section, navigate to ‘Advanced’ tab, then click on the blue Manage button located beside the Database section.

You are now going to a different cPanel tab. From the ‘Modify Databases’ menu, find and select the name of your database in the Repair Database dropdown menu.

Now, click on the database and it will begin the process.

cPanel will start the process of repairing your database automatically.

In cPanel the repair progress is carried out within the same section, and a progress indicator displays the work done. When finished, you will see success messages.

Change Database Password

Success messages will appear after each stage indicating the completion of database repair tasks.

You have now got the option to check the WordPress site to see the error status and confirm if it has been fixed.

Check If Your Database Server Is Down

If everything seems fine, but WordPress still cannot connect to the database, then it is possible that your database server (MySQL server) is down.

This often happens when there is a lot of traffic on the server. This issue occurs more on shared hosting because the server cannot handle so much load.

This can cause your site to slow down or some users may also see a database connection error. In such a case, you should talk to your hosting provider on live chat or phone call and ask if their MySQL server is working properly or not.

In case you own any other website which is hosted on the same server, you can check that website to see if the SQL server is down.

If you don’t own any other websites, just log in to your hosting control center and navigate to the ‘Advanced’ Section.

From there, click the Manage button next to phpMyAdmin.

This will open phpMyAdmin in a new window. There you will have to click on the ‘Database’ option above.

Next choose your database so that you can see its settings. Completing this means checking if your database user has the right permissions in the next step.

Connecting to your database from phpMyAdmin: For this you need to create a new file named: testconnect.php And paste the following code in it:

<?php
$link = mysqli_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>

Replace the username and password here with your actual database credentials. Now upload this file to your website and open it in the browser. If you get the message “Connected successfully“, it means your user has the correct permissions. Then the error is occurring due to some other reason. Now you have to go back to the wp-config.php file and check every detail carefully for spelling mistakes, extra spaces or any typos.

Fix WordPress Redirects: https://wpguidepro.com/fix-wordpress-redirects-to-spam-in-minutes/

Resolve 500 Internal Server: https://wpguidepro.com/resolve-500-internal-server-error-in-wordpress/

Technical Errors in WordPress: https://wpguidepro.com/simple-fixes-for-technical-error-in-wordpress/

Fix WordPress Syntax Error: https://wpguidepro.com/fix-wordpress-syntax-error-2-easy-tips/

WordPress Error Logs: https://wpguidepro.com/wordpress-error-logs-steps/

Related Articles

- Advertisement -spot_img

Latest Articles