Get the App
SLTechnology News&Howtos  ›  Database  › 

What are the ways for MySQL to change a user's password?

Shulou Source: shulou.com Published: 2022-06-01 04:26:03 10月30日 Update

Xiaobian to share with you what MySQL ways to change the user's password, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

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

1 、 UPDATE

2 、 SET PASSWORD

3 、 ALTER USER

But before changing your account password, there are two very important things to keep in mind:

1. Details of the user account to change the password.

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

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

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

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

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

To change the password of the user account "gfguser1" to "newpass" using the SET PASSWORD statement, execute the following code statement:

Syntax:

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

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

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

Syntax:

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.

The Update statement updates the user table of the mysql database.

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

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

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

Syntax:

The above are all the contents of MySQL's method of changing the user's password. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Password user statement account method application data database program grammar application content syntax server permission in progress article learning update service Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL NVidia Redmi vpn