w3resource

Guide to Updating MySQL user Password


Change a User's Password

Write a MySQL query to update the password of the user "alice" to "NewPass456".

Solution:

-- This command modifies the existing user 'alice' by changing their password
-- Sets a new password 'NewPass456' for connections from localhost
ALTER USER 'alice'@'localhost' IDENTIFIED BY 'NewPass456'; 

Explanation:

  • Purpose of the Query:
    • The goal is to update a user's password to enhance security.
    • This demonstrates the ALTER USER statement for modifying user credentials.
  • Key Components:
    • ALTER USER : Specifies the command to modify user details.
    • 'alice'@'localhost' : Identifies the user whose password is being changed.
    • IDENTIFIED BY 'NewPass456' : Sets the new password.
  • Real-World Application:
    • Essential for periodic security updates or password resets after a potential compromise.

Notes:

  • Ensure the new password complies with your organization's security policies.

For more Practice: Solve these Related Problems:

  • Write a MySQL query to change the password for "alice"@'localhost' to "NewStrong!@#789".
  • Write a MySQL query to update the password for "bob"@'%' using the appropriate authentication plugin.
  • Write a MySQL query to modify the password for "charlie"@'192.168.1.200' and enforce a password expiration policy.
  • Write a MySQL query to update the password for "david"@'remote.host.com' ensuring the new password meets complexity requirements.


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous MySQL Exercise: Revoke a Role from a User.
Next MySQL Exercise: Show user Privileges.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.