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

How to change MySQL user password using UPDATE statement?

WBOY
Release: 2023-09-03 19:37:06
forward
1589 people have browsed it

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;
Copy after login

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< /strong> is the new password we want to set for the MySQL user
  • User_name is the name of the current user.
  • Host_name 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(&#39;tutorials&#39;)
WHERE user = &#39;user&#39; AND
   host = &#39;localhost&#39;;
FLUSH PRIVILEGES;
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template