Are you seeing the ‘Error establishing a database connection’ notice on your WordPress website? It is a fatal error that makes your WordPress website inaccessible to users.
This error occurs when WordPress is unable to make a connection to the database. A number of things can affect your WordPress database connection which makes it a bit difficult for beginners to troubleshoot. In this article, we will show you how to easily fix the error by establishing a database connection in WordPress.
What Causes is Error Establishing a Database Connection in WordPress?
The ‘Error establishing a database connection issue can be caused by incorrect database information in your WordPress settings, corrupt database, or an irresponsive database server.
A database is a software that makes it easy to store, organize, and retrieve data from other software. As a content management system, WordPress uses a database to store all your content and other website data. It then connects to the database each time someone visits your website. As a content management system, WordPress uses a database to store all your content and other website data. It then connects to the database each time someone visits your website.
WordPress needs the following information for connecting to the database:
Database name
Database Username
Database password
Database server
This information is stored in your WordPress configuration file called wp-config.php.
If any of these items are incorrect, WordPress would fail to connect to your database server, and you’ll see the ‘Error establishing a database connection error.
Check Your WordPress Database Credentials
The most common reason for database connection errors in WordPress is incorrect database credentials. If you have recently moved your WordPress site to a new host, then this could be the most likely reason. Your WordPress database credentials are stored in the wp-config.php file. It is the WordPress configuration file that contains important WordPress settings including database information.
If you have not edited the wp-config.php file before, then take a look at our guide on how to edit the wp-config.php file in WordPress.You’ll be looking for the following lines in the wp-config.php file.
You need to make sure that the information for the database name, username, password, and database host is correct. You can confirm this information from your WordPress hosting account dashboard. Simply log in to your hosting account and click on MySQL databases under the database section.
We’re using the HostGent dashboard in our screenshot, but the process will be similar in other hosting control panels.
This will take you to the database management page in your hosting dashboard. From here, you can find out your database name and username. Below that you will find the database users and links to change the user password.
Once you have confirmed your database name, username, and password, you can change that information in your wp-config.php file if needed. After that, try visiting your website again to see if the database connection error has gone.
If you can still see the error, then this means that something else is wrong. Continue reading for more troubleshooting steps.
Check Your Database Host Information
If you are confident that your database name, username, and password information is correct, then you may want to make sure that you are using the correct database host information. Most WordPress hosting companies use localhost as your database host. However, some managed WordPress hosting companies use separate servers to host databases. In that case, your database host information will not be localhost.
You need to contact your WordPress hosting company to confirm your database host information.
Repair WordPress Database
If you are getting a different error on the wp-admin, for instance, something like “One or more database tables are unavailable. The database may need to be repaired”, then you need to repair your database. You can do this by adding the following line in your wp-config.php file. Make sure to add it just before ‘That’s all, stop editing! Happy blogging’ line wp-config.php.
Other Solutions That Have Worked for Users
If the above-mentioned troubleshooting tips failed to fix the database connection error on your website, then you may try these additional steps.As reported by our users, these steps have helped some users resolve the database connection error on their websites.
Update WordPress Site URL
Try updating the WordPress site URL using phpMyAdmin. Simply access phpMyAdmin from your hosting account dashboard, and select your WordPress database.
Rebooting Web Server
Users on dedicated servers, local servers, and virtual private servers (VPS) can try rebooting their servers. This will restart your web and database server which may fix some temporary glitches causing the error.
Ask for help
If everything else fails, then you may need to contact our team. we’ll fix it for you. you can contact us