This tutorial explains how to change a user's password in MySQL with syntax and examples.
The SET PASSWORD statement is used to change a user's password in the MySQL database.
The syntax for changing a password using the SET PASSWORD statement in MySQL is:
Optional. It is the user whose password you wish to change. If user_name is not specified, the password will be changed for the current user (see CURRENT_USER function).
First method to set password. Uses the PASSWORD function to take the plaintext text string found in plaintext_password1 and generate a hashed password (using hashing techniques MySQL 4.1+).
Second method to set password. Uses the OLD_PASSWORD function to take the plaintext text string found in plaintext_password2 and generate a hashed password (using hashing techniques prior to MySQL 4.1).
Third method to set password. A password that is already encrypted using the authentication method for the user account that does not need to be modified any further.
Let's look at an example that shows how to use the SET PASSWORD statement in MySQL.
For example, if you wanted to update the user named ao with the password autumn, you would run the following SET PASSWORD statement in MySQL:
If you wanted to reset the password using the hashing techniques prior to MySQL 4.1, you would modify the SET PASSWORD statement as follows:
If the new password was already encrypted, you could use the SET PASSWORD statement as follows: