MySQL Change user password

Configurare noua (How To)

Situatie

To change the user password in MySQL, users can use the UPDATE statement, SET PASSWORD statement, and ALTER USER statement. All three of these statements can be used to change the MySQL user password.

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.

Solutie

Pasi de urmat

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 the “user@host” format whose password you want to update.

Syntax:

SET PASSWORD FOR 'username'@'host' = 'newpassword';

Example: To change the password for the user account ‘gfguser1' connecting from ‘localhost' to ‘newpass'.

Changing MySQL User Password Using The ALTER USER statement

The second way to change the password for a user account is to use the ALTERUSER statement. The ALTER USER statement is used along with the “IDENTIFIED BY” clause.

Syntax:

ALTER USER 'username'@'host' IDENTIFIED BY 'newpassword';

Example: To change the password for the user account ‘gfguser1' connecting from ‘localhost' to ‘newpass'.

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.

Syntax:

UPDATE mysql.user 
SET authentication_string = PASSWORD('newpassword') 
WHERE User = 'username' AND Host = 'host';
FLUSH PRIVILEGES;

Tip solutie

Permanent

Voteaza

(2 din 4 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?