Home  >  Article  >  Database  >  How to change MySQL user password using UPDATE statement?

How to change MySQL user password using UPDATE statement?

WBOY
WBOYforward
2023-09-03 19:37:061545browse

How to change MySQL user password using UPDATE statement?

To change the MySQL user password with the help of UPDATE statement, we need to update the "user" table of the "mysql" database. Its syntax is as follows -

Syntax

USE mysql;
UPDATE user
SET authentication_string = PASSWORD(‘new_password’)
WHERE user = user_name AND host = host_name;

The first two statements are very common because to change the password of a MySQL user, we need to use the MySQL database and update the user table.

  • New_password is the new password we want to set for the MySQL user
  • User_name is the name of the current user.
  • Host_name strong> is the host name of the current user.

Example

Suppose 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;

The above is the detailed content of How to change MySQL user password using UPDATE statement?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete