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, making it a bit hard for beginners to troubleshoot.
This article 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 throws this error.
What is a Database?
A database is software that makes it easy to store, organize, and retrieve data into other software.WordPress utilizes 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.
- Database Name
- Database Username
- Database Password
- Database Server
WordPress stores 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 the Error Establishing a Database Connection issue in WordPress.
Verify Your WordPress Database Credentials
Wrong database credentials are the usual reason for database connection errors 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 the DirectAdmin control panel.
Click on the File Manager under System Info & Files section.
Now open the 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 to make sure that the Database Name, Database Username, Database Password, and Database Server are 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.
On the Users page, you can take various actions to your database.
- Create New User
- Add Existing User
- Delete User
- Change Password
- Modify Privileges
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 in troubleshooting 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.
If you enjoyed this tutorial, then you’ll love Rovity and our fast-growing premium shared hosting on the cloud. Check our subscription plans.