Resolving the error message “Error Establishing a Database Connection” in WordPress can be frustrating, but with the right steps, you can get back online quickly. This error means that WordPress cannot connect to the database, an essential component for the functioning of your website. Below is a clear guide to solve this problem.
Check the Database Data
The most common cause of this error is incorrect database information in your wp-config.php file. This file contains your database name, username, password and server information.
- Getting access to wp-config.php: Connect to your website via FTP, such as FileZilla, or use the File Manager in your hosting control panel. (More explanation of how FTP works? Click here )
- Verify the database information: Open the wp-config.php file and verify the following values:
DB_NAME
– The name of the database that WordPress uses.DB_USER
– The username used to access the database.DB_PASSWORD
– the password associated with this username.DB_HOST
– the database server, oftenlocalhost
but some hosts use a specific IP address or URL.
Make sure this information exactly matches the information provided by your hosting provider.
Test the Database Connection
If your database information is correct, test whether your server can actually connect to the database. You can do this by creating a simple PHP file:
- Create a new PHP file: for example, name it
testconnection.php
. - Add the following code:
<?php $link = mysqli_connect('DB_HOST', 'DB_USER', 'DB_PASSWORD', 'DB_NAME'); if (!$link) { die('Connect Error: ' . mysqli_connect_error()); } echo 'Success: A proper connection to MySQL was made!'; mysqli_close($link); ?>
ReplaceDB_HOST
,DB_USER
,DB_PASSWORD
, andDB_NAME
with your own data. - Upload this file to your server and visit it in your web browser(http://jouwwebsite.com/testconnection.php)
Check for Database Corruption
In some cases, the error message may be caused by a corrupt database. You can check this and fix it if necessary through the WordPress dashboard:
- Go to
www.jouwwebsite.com/wp-admin
. - If the error occurs there as well, try fixing the database by adding the following line to your wp-config.php file:
define('WP_ALLOW_REPAIR', true);
- Then visit
www.jouwwebsite.com/wp-admin/maint/repair.php
and choose the option to repair the database.
Delete this line from your wp-config file once you are done for security reasons.
By following these steps, you should be able to resolve the “Error Establishing a Database Connection” error in WordPress. Remember to always back up before making changes to your website.
Do you have other questions or can’t figure it out? Then please contact us.
Receive more tips? Then subscribe to our newsletter.