How to reset a user password in mysql 8?

Member

by domenico , in category: MySQL , a year ago

How to reset a user password in mysql 8?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raven_corwin , 9 months ago

@domenico 

To reset a user password in MySQL 8, you can follow these steps:

  1. Log in to MySQL with an account that has administrative privileges. mysql -u root -p
  2. Once you are logged in, switch to the MySQL system database: use mysql;
  3. Run the following command to update the user's password: ALTER USER 'username'@'localhost' IDENTIFIED BY 'new_password'; Replace 'username' with the actual username for which you want to reset the password and 'new_password' with the desired new password.
  4. If the user is not restricted to localhost only and can access from any host, use the following command instead: ALTER USER 'username'@'%' IDENTIFIED BY 'new_password';
  5. After executing the command, you need to flush the privileges so that the changes take effect: FLUSH PRIVILEGES;
  6. Exit the MySQL prompt by typing: exit;


The user's password should now be reset to the new password you provided.