# mysql -u root -p
mysql> SET PASSWORD FOR ‘user’@’hostname’ = PASSWORD(‘passwordhere’);
mysql> flush privileges;
To change a user’s password in MySQL from the MySQL prompt while logged in as the root user, you can use the following steps:
- Log in to MySQL as the root user:
mysql -u root -p
You will be prompted to enter the root password.
- Change the user’s password:
ALTER USER 'username'@'host' IDENTIFIED BY 'new_password';
Replace ‘username’ with the actual username, ‘host’ with the actual host or ‘%’ for any host, and ‘new_password’ with the desired new password.
For example, to change the password for a user named ‘john’ with any host:
ALTER USER 'john'@'%' IDENTIFIED BY 'new_password';
- Optionally, you may want to flush privileges to apply the changes immediately:
FLUSH PRIVILEGES;
This step ensures that the changes take effect without having to restart the MySQL server.
Remember to replace ‘username’, ‘host’, and ‘new_password’ with your actual values.