- Go to: 'System Preferences' >> 'MySQL' and stop MySQL
OR,
- sudo /usr/local/mysql/support-files/mysql.server start
- sudo /usr/local/mysql/support-files/mysql.server stop
- sudo /usr/local/mysql/support-files/mysql.server status
-
Make sure you have Stopped MySQL first (above).
-
Run the server in safe mode with privilege bypass:
sudo mysqld_safe --skip-grant-tables
-
In a new window connect to the database, set a new password and flush the permissions & quit:
mysql -u root
-
For MySQL older than MySQL 5.7 use:
UPDATE mysql.user SET Password=PASSWORD('rootpass') WHERE User='root';
For MySQL 5.7+ use:
UPDATE mysql.user SET authentication_string=PASSWORD("rootpass") WHERE User='root';
-
Now flush privileges:
FLUSH PRIVILEGES;
-
Restart MySQL server.
-
More info: http://stackoverflow.com/questions/6474775/setting-the-mysql-root-user-password-on-os-x
Update: On 8.0.15 (maybe already before that version) the PASSWORD() function does not work You have to do:
I am using MYSQL 8.0.28 on mac m1 and this worked for me, but make sure you close down MYSQL safe start before restarting it after this process and your new password set here will work