The most common cause of a database connection error in WordPress is incorrect database credentials. If you have recently moved your WordPress site to a new host, this may be the most likely reason.
Your WordPress database credential is stored in the wp-config.php file. This is a WordPress configuration file containing important WordPress settings including database information.
If you have not edited the wp-config.php file before, take a look at our guide on how to edit the wp-config.php file in WordPress.
You can verify this information from your WordPress hosting account panel. Just log into your hosting account and click on MySQL database under the data section.
This will take you to the database management page in your hosting dashboard. From here, you can find the name and username of your database.database users and links to change the user password.
Once you confirm your database name, username and password, you can change that information in your wp-config.php file if needed.
After that, try again on your website to see if a database connection error has occurred.
If you can still see the error, it means that something else is wrong. Continue reading for more troubleshooting
If you are sure that your database name, username and password information are correct, you want to make sure that you are using the correct web host information.
Most WordPress hosting companies use some WordPress hosting companies use separate servers to host the database. In this case, your database host will not be local.
You will need to contact your WordPress hosting company to confirm your database host information.
For example, if you get another error in wp-admin, “One or more databases are unavailable. Your database needs to be repaired, ”your database needs to be restored.
You can do this by adding the following line to your wp-config.php file: ‘All this, add it, make sure you add it immediately before you stop editing. Congratulations bloggers wp-config.php
If everything seems right, and WordPress still cannot connect to the database, your database server (MySQL server) may be down.
This can happen due to heavy traffic on the server. Basically, your host server just can’t handle the load (especially when you’re on shared hosting).
Your site will be really slow and may cause this error for some users. So the best thing you should do is get on the phone or chat live with your hosting provider and ask them if your MySQL server is responsive.
If you have other websites running on the same server, you can check those sites to see if your SQL Server is down.
If you do not have another site on the same hosting account, just go to your hosting dashboard and try to access phpMyAdmin and connect to the database.
If you can connect, we need to verify whether your database user has sufficient permission. Create a new file named testconnection.php and paste the following code in it:
'Could not connect: '
Be sure to change the username and password. Now you can upload this file on your website and access it through a web browser.
If the script is successfully attached, it means that your user has enough permission, and there is something else that is wrong.
If the above troubleshooting tips failed to fix a database connection error on your website, you can try these additional steps.
Reported by our users, these steps have helped some users to resolve database connection error on their websites.