In this article, you will learn to resolve the problem that occurs after a server is upgraded to MySQL 5.6.5 or later.
In case you don’t know which MySQL version is installed on your server, follow these steps:
- Log in to cPanel.
- Go to the right sidebar of the cPanel home screen, under General Information, click Server Information.
- Under Server Information, locate the MySQL Version row to check the MySQL version installed on the server.
Problem
When accessing a database on the server running MySQL 5.6.5 or later, the login fails even if you have been using the correct username and password.
For instance, while running WordPress on your site, you see the below error message:
Error establishing a database connection
Also with other web applications, similar messages may get displayed about database connection errors.
Cause
The cause of this issue is the use of a new hashtag method for user passwords by MySQL 5.6.5. The further MySQL versions don’t support the hash method, used in older versions of MySQL to store passwords and so the logins fail.
Resolution
For resolving this issue, you should delete and recreate the database user. While doing this, the new hash method is used by MySQL to store the password, and the database user can log in again.
To do this, follow the below steps:
- Log in to your cPanel account.
- Go to the Databases section of the cPanel home screen and click on MySQL® Databases.
- Then locate the database user that you want to recreate under Current Users and click Delete.
- In order to confirm the deletion, click Delete User and then click on Go Back.
- Under Add New User, in the Username text box, type the username of the user you deleted just now.
- In the Password text box, type the user password.
Note: There is no need to create a new password for the user. The previous password can be used, if you want to keep the password unchanged. For finding the current password, check your application’s configuration files. For example, for WordPress, you will need to check the wp-config.php file for database configuration information. - Retype the user password in the Password (Again) text box.
Note: As an alternative, you can click Password Generator and cPanel will generate a random, strong password for you. - Now click on Create User. cPanel creates the database user with the new hashing method to store the password.
In this way, you can resolve the error “Error establishing a database connection”.