Change a Password for MySQL

First we’ll login to the MySQL server from the command line with the following command:
mysql -u root -p
In this case, I’ve specified the user root with the -u flag, and then used the -p flag so MySQL prompts for a password. Enter your current password to complete the login.
Now switch to the appropriate MySQL database with the following command:
use mysql;
Next we’ll update the password for all MySQL users with the name root. Be sure to replaceyour_new_password with the actual new password:
update user set password=PASSWORD(‘your_new_password’) where User=’root’;
Note: You can change the password for any user with the above command. Simply specify that user’s username in place of root.
Finally, reload the privileges:
flush privileges;
Now you’re all set to exit MySQL!
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=PASSWORD(“redhat2019”) where User=’root’;
ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’

Be the first to comment

Leave a Reply

Your email address will not be published.