To ensure database security, root and all other users must have strong passwords configured. 

Once the MySQL server is installed, we can connect to the server by default as the root user. Sometimes it's necessary to set or modify the password for root or any other existing user for security reasons.

You will discover how to modify the password for any current MySQL user on Ubuntu.

First, log in to your server via root access.

You can connect to the MySQL database server by using the following command if the root user's password is not configured:

mysql -u root 

or

sudo mysql -u root

You can connect to the MySQL database server by using the following command if the root user's password is configured:

mysql -u root -p

or

sudo mysql -u root -p

Second,  you will need to enter the MySQL root user password for login (if the root user password is configured). You will get some kind of below view

 

Using the following command, you can additionally add a host column to get even more details: You will be able to see the MySQL users and the hosts or IP addresses that they are authorized to access with this. In our scenario, every user comes from a nearby database:

select user, host FROM mysql.user;


Third, you need to update your password. The commands listed below will assist you in updating your user password.

If the user's host location is %, then run the below command:

 ALTER USER 'user'@'%' IDENTIFIED BY 'password';

Note: The place '%' should update according to the user host or IP address from the above image file. You will get to know the details above the image information. 


Finally run below command;

FLUSH PRIVILEGES;


After that, run the below command for the MySQL service restart.

sudo service mysql restart


Everything is now okay. You updated the MySQL user password. Hopefully, this article has helped you understand how to update your MySQL user password.

Share