If you get a Database error that states “Critical Error – Unable to connect to the Database “, then it would be due to the following:
- Incorrect database username and password credentials
- Wrong privileges to the database
Verify the username and password that you are trying to connect to the database. Confirm this in the configuration file within your application installation root directory. If that is correct, you can rule out that reason.
Next verify if the MySQL user has the necessary permission to the database. Follow the below steps on cPanel or Command Line.
If you are familiar with command line follow the below steps:
1. Login to MySQL Using below command
mysql -u user -p
Where user will be the username
2. Enter the password when prompted
3. Give all privileges to this user on the database
GRANT ALL PRIVILAGES ON db_name.* TO ‘user_name’@’localhost’;
Where db_name will be the database name and the user_name will be the username
If you want to perform the same via cPanel, follow the below steps:
- Log in to your cPanel account and then on Databases section select MySQL Databases.
- Also, scroll down and you will see Add User to Database section.
- Select user and database, on which you want to give privileges to the selected user. Click ‘Add’ button.
- You will be redirected to a new page as shown below:
- Select all privileges and click ‘Make Changes’ Button.
If you have confirmed the above and still the error “Critical Error – Unable to connect to the Database” persists, please contact your server administrator.