Cover Image for MySQL Change User Password
83 views

MySQL Change User Password

To change a user’s password in MySQL, you can use the ALTER USER statement or the SET PASSWORD statement, depending on your MySQL version. Here’s how to do it using both methods:

Using ALTER USER (MySQL 5.7 and later):

You can change a user’s password using the ALTER USER statement. This method is available in MySQL 5.7 and later:

ALTER USER 'username'@'host' IDENTIFIED BY 'new_password';
  • 'username': Replace this with the name of the user for whom you want to change the password.
  • 'host': Specify the hostname or IP address associated with the user.
  • 'new_password': Set the new password you want to assign to the user.

Example:

ALTER USER 'myuser'@'localhost' IDENTIFIED BY 'newpassword';

This statement changes the password for the ‘myuser’ account when connecting from localhost.

Using SET PASSWORD (MySQL 5.6 and earlier):

If you are using MySQL 5.6 or earlier, you can change the password using the SET PASSWORD statement:

SET PASSWORD FOR 'username'@'host' = PASSWORD('new_password');
  • 'username': Replace this with the name of the user for whom you want to change the password.
  • 'host': Specify the hostname or IP address associated with the user.
  • 'new_password': Set the new password you want to assign to the user.

Example:

SET PASSWORD FOR 'myuser'@'localhost' = PASSWORD('newpassword');

This statement changes the password for the ‘myuser’ account when connecting from localhost.

After executing either of these statements, the user’s password will be updated with the new value you provided.

Remember that you may need the appropriate privileges to modify user accounts or set passwords, such as the ALTER privilege on the user or the UPDATE privilege on the mysql database. Always ensure that you have the necessary permissions to make these changes.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS