How to change user password in MySQL? (code example)

藏色散人
Release: 2019-03-16 11:13:00
Original
3719 people have browsed it

How to change user password in MySQL? (code example)

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

UPDATE statement SET PASSWORD statement ALTER USER statement.
Copy after login

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

- The user account details for which the password is to be changed.

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

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

1. Change MySQL user password using SET PASSWORD statement

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

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

You want to use the SET PASSWORD statement to change the password of user account "gfguser1" to "newpass", you should execute the following code statement:

Syntax:

How to change user password in MySQL? (code example)

2. Use the ALTER USER statement to change the MySQL user password

The second method of changing 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? (code example)

3. Use the UPDATE statement to change the MySQL user password

The third way 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? (code example)

This article is about the method of changing user password in MySQL. Recommended related mysql video tutorials: "mysql tutorial"

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

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!