The ‘Error Establishing a Database Connection’ warning on your WordPress website is a fatal error.
This error causes your WordPress website unavailable to your website visitors.
When WordPress is unable to establish a connection to the database, this error happens.
Many things can affect your WordPress database connection, which makes it a bit hard for beginners to troubleshoot.
In this article, you can learn how to fix the Error Establishing a Database Connection in WordPress quickly.
Why Do You See Error Establishing a Database Connection in WordPress?
Incorrect database information in your WordPress settings causes the ‘Error Establishing a Database Connection.’
A corrupt database or an unresponsive database server also throw this error.
What is a Database?
WordPress utilises a database to store all your content and other data.
Every time someone visits your website, WordPress connects to the database.
For connecting to the database, WordPress requires the following information.
WordPress store this information in the wp-config.php file. This wp-config.php file is the WordPress configuration file.
WordPress will fail to connect to your database server if any of these values are incorrect.
With this step by step troubleshooting, let us see how to fix Error Establishing a Database Connection issue in WordPress.
Verify Your WordPress Database Credentials
Wrong database credentials are the usual reason for database connection error in WordPress.
Have you migrated your WordPress site to a new host recently? Then this could be the most likely reason.
The wp-config.php file saves your WordPress database credentials.
This WordPress configuration file holds critical WordPress settings.
To check the values in the wp-config.php file, log in to DirectAdmin control panel.
Click on the File Manager under System Info & Files section.
Now open public_html folder.
Mouse hover on wp-config.php and click on the Edit File.
Take a look at the following lines in your wp-config.php file.
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' );
It would be best if you made sure that the information for the Database Name, Database Username, Database Password and Database Server is correct.
You can verify this information from your DirectAdmin dashboard.
Log in to your DirectAdmin account and click on MySQL Management under the Account Manager section.
You can now see the MySQL Management page with all the Databases listed.
From here, click on the database name associated with your WordPress website.
Create New User
Add Existing User
Change WordPress Database Password
If you are unsure about the database password or wish to update it, click on the Change Password link.
In this CHANGE PASSWORD pop up, you can Generate Random Password or input a password.
You can toggle hide and show on clicking the eye icon.
You can copy the password to your clipboard as well.
Now click on the Change button, and the database password will update.
Have you confirmed your database name, username, and password?
You can now modify that information in your wp-config.php file if needed.
Now try revisiting your website to see if the database connection error has gone.
Do you still see the error? Then that means something else is incorrect.
All great WordPress hosting companies can support you troubleshoot the problem. Or point you in the correct direction to fix it yourself.
Have you hosted your WordPress website with us?
Then create a support ticket, and we are happy to fix it for you.