1. Check Your WordPress Database Credentials
The most common reason for database connection error in WordPress is incorrect database credentials.
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.
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.
a. Simply log in to your hosting account and click on MySQL databases under the database section.
b. This will take you to the database management page in your hosting dashboard. From there, you can find out your database name and the username.
c. Once you have confirmed your database name, username, and password, you can change that information in your wp-config.php file if needed.