Mysql user password can be changed using the MySQL command-line client or the workbench, which comes pre-installed with MySQL.
MySQL Change User Password using Update
Using update, we can change the user password and make changes to the user.
USE DB;
UPDATE user
SET password = PASSWORD('mulvan')
WHERE user = 'ash' AND
host = 'localhost';
FLUSH PRIVILEGES;
- Use the database where the user is present.
- Update user and then set password where user and host match the specified name.
- Flush privileges, in the end, to reload privileges from the grant table in the DB database.
Note that from MySQL 5.7.6, we need to use authentication_string in the place of a password to make a change.
USE DB;
UPDATE user
SET authentication_string = PASSWORD('mulvan')
WHERE user = 'ash' AND
host = 'localhost';
FLUSH PRIVILEGES;
MySQL Change User Password Using SET PASSWORD Statement
We can use the SET PASSWORD statement specifying the user@host and then followed by password after an equals.
SET PASSWORD FOR 'username'@'localhost' = newpassword;
We don't need to use the flush privileges to use the SET PASSWORD.
Alter User Change Password MySQL
ALTER USER followed by the user@hostname with the statement 'identified by' is used here.
ALTER USER username@localhost IDENTIFIED BY 'newpassword';
The root password can be changed by force stopping the MySQL database server from stopping and restarting without grant validation.
- Log in to post comments