How to Reset Change the MySQL root password in Linux, Mac, Unix

If you have forgotten the password set for root and need to reset your password, please follow these steps:

1. Stop the mysqld server, which varies by installation

2. Use permission bypass to run the server in secure mode

sudo mysqld_safe --skip-grant-tables;
3. Connect to the database in a new window, set a new password and refresh the permissions and exit:mysql -u root

4. For MySQL earlier than MySQL 5.7, use:

UPDATE mysql.user SET Password = PASSWORD('your-password')WHERE User ='root';

For MySQL 5.7+ use:

Use mysql;UPDATE mysql.user SET authentication_string = PASSWORD("your-password")WHERE User ='root';

Refresh and exit:


5. Stop the secure mode server and restart the regular server. The new password is now ready to use. It’s like a charm to me 🙂