In this tutorial, I will show you the way to reset MySQL root password in macOS.
Note: I work with MySQL 5.7.x for this tutorial,
First of all, we need stop MySQL server using MySQL Start/Stop Configuration as below:
Then, open Terminal and start MySQL server in safe mode:
1 |
sudo mysqld_safe --skip-grant-tables |
Next, open other Terminal and try to login with user root without password:
1 |
mysql -u root |
Update password for root user by using following command:
1 |
UPDATE mysql.user SET authentication_string=PASSWORD('<enter_your_password_here>') WHERE User='root'; |
Update privileges:
1 |
FLUSH PRIVILEGES; |
Now, you can login user root with your password.
But right now, if you try to execute any SQL statements, you will get the messages as below:
To resolve this message, you must execute again the statement to update the password:
1 |
SET PASSWORD=PASSWORD('enter_your_password_here'); |
Now, you can execute your statement.