Home  >  Article  >  Database  >  How to change user password in MySQL

How to change user password in MySQL

藏色散人
藏色散人Original
2019-02-19 15:43:224235browse

In MySQL, you can use 3 different statements to change the user account password:

How to change user password in MySQL

1, UPDATE

2, SET PASSWORD

3. ALTER USER

But before changing the account password, you should remember two very important things:

1. The details of the user account whose password you want to change.

2. The user who is changing the password is using the application because if the password is changed without changing the application's connection string, the application will not be able to connect to the database server.

Now let us learn how to use the three SQL statements mentioned above to change the user password in SQL:

1. Use the SET PASSWORD statement to change the MySQL user password:

To change a user's password using the SET PASSWORD statement, the first requirement is that the account needs to have at least UPDATE permission.

The user account should be in "user@host" format and you want to update its password.

To use the SET PASSWORD statement to change the password for user account "gfguser1" to "newpass", the following code statement should be executed:

Syntax:

How to change user password in MySQL

2. Use the ALTER USER statement to change the MySQL user password: The second method to change the user account password is to use the ALTER USER statement.

ALTER USER statement is used with the "IDENTIFIED BY" clause.

To use the Alter User statement to change the password of user account "gfguser1" to "newpass", the syntax is as follows:
Syntax:

How to change user password in MySQL

3. Use the UPDATE statement to change the MySQL user password: The third method to change the user account password is to use the UPDATE statement.

Update statement updates the user table of the mysql database.

The FLUSH PRIVILEGES statement needs to be executed after the UPDATE statement is executed.

FLUSH PRIVILEGES statement is used to reload permissions from the grant table in the mysql database.

To change the password of user account "gfguser1" to "newpass" connecting from the localhost server, the syntax is as follows:

Syntax:

How to change user password in MySQL

Recommended tutorial: "mysql tutorial"http://www.php.cn/course/list/51.html

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

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