Skip to content
Related Articles

Related Articles

Improve Article

MySQL | Change User Password

  • Difficulty Level : Basic
  • Last Updated : 03 Mar, 2018

In MySQL, the user account password can be changed using 3 different statements:

  1. UPDATE statement
  2. SET PASSWORD statement
  3. ALTER USER statement.

But before changing the password of an account, two very important things should be kept in mind:

  • The user account details for which you want to change the password.
  • The application is being used by the user whose password you are going to change because if the password is changed without changing the connection string of the application then the application will not be able to connect to the database server.

Let us now learn about how to change the user password in SQL using the three above mentioned SQL statements:

  1. Changing MySQL User Password Using The SET PASSWORD Statement: To change the user password using the SET PASSWORD statement the first requirement is that the account needs to have at least UPDATE privilege.

    The user account should be in “user@host” format whose password you want to update.



    To change the password of a user account “gfguser1” to “newpass” using the SET PASSWORD statement, the following code statement should be executed:

    Syntax:

  2. Changing MySQL User Password Using The ALTER USER statement: The second way to change the password for a user account is to use the ALTER USER statement.

    The ALTER USER statement is used along with the “IDENTIFIED BY” clause.

    To change the password for the user account “gfguser1” to “newpass” using the Alter User statement, syntax is as shown below:
    Syntax:

  3. Changing MySQL User Password Using UPDATE Statement: The third way to change the password of a user account is by using the UPDATE statement.

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

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

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

    To change the password for the user account “gfguser1” to “newpass” that connects from the localhost server, syntax is as shown below:

    Syntax:

My Personal Notes arrow_drop_up
Recommended Articles
Page :