To change MySQL user password with the help of UPDATE statement, we need to update the ‘user’ table of the ‘mysql’ database. Its syntax would be as follows −
USE mysql; UPDATE user SET authentication_string = PASSWORD(‘new_password’) WHERE user = user_name AND host = host_name;
The first two statements will be common because to change the password for MySQL user we need to use MySQL database and update the user table.
Suppose if we want to change the password user@localhost to ‘tutorials’ then it can be done as follows −
USE mysql; UPDATE user SET authentication_string = PASSWORD('tutorials') WHERE user = 'user' AND host = 'localhost'; FLUSH PRIVILEGES;