How to Change a users password from MySQL prompt. Login as root. Set the password. Update privs

# 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:

  1. Log in to MySQL as the root user:
sql
mysql -u root -p

You will be prompted to enter the root password.

  1. Change the user’s password:
sql
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:

sql
ALTER USER 'john'@'%' IDENTIFIED BY 'new_password';
  1. Optionally, you may want to flush privileges to apply the changes immediately:
sql
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.