Those of you familiar with MAMP will no doubt know that MAMP’s MySQL root user password is set to root by default and changing it is not as straightforward as it perhaps should be.
I’ve previously described a way of successfully changing the root user password providing, of course, that you know the current password. If you’ve forgotten it, this method will not work and a way of re-setting the password is required.
I’ll be using the Terminal to reset the root password, but first we need to ensure that MAMP’s MySQL server is not running.
If MAMP is running and the Stop Servers when quitting MAMP option is checked then quitting MAMP will suffice.
If not, click the Stop Servers button.
Next, start MAMP’s MySQL server from the Terminal with the --skip-grant-tables option. As this option allows anyone to connect without a password and with all privileges — albeit temporarily — the --skip-networking option is included to prevent remote access.
Copy and paste the following command into a Terminal window and press enter:
/Applications/MAMP/Library/bin/mysqld_safe \ --skip-grant-tables \ --skip-networking \ --socket=/Applications/MAMP/tmp/mysql/mysql.sock \ --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid &
When Terminal displays the following message, press enter again to return to the Terminal prompt.
mysqld_safe Starting mysqld daemon with databases from /Applications/MAMP/db/mysql
At the prompt type the following command to access the MySQL command interpreter:
You should see the MySQL command interpreter prompt: mysql>
At the prompt type:
Press enter, then type the following replacing NewPassword with the password of your choice:1
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('NewPassword');
Press enter, then type:
Press enter. Then, to quit the MySQL command interpreter type:
You should be returned to the Terminal prompt. Copy and paste the following command to shutdown MAMP’s MySQL server. You’ll be prompted for the new root password when you press enter.
/Applications/MAMP/Library/bin/mysqladmin \ --socket=/Applications/MAMP/tmp/mysql/mysql.sock shutdown -u root -p
Having reset the root user password you should follow the instructions here regarding updating the necessary files in MAMP with the new password.
These instructions were adapted from the official MySQL documentation.
1 As of MySQL v5.7.6 the PASSWORD() function has been deprecated. This doesn’t affect the current version of MAMP – v4.4 released 2018-02-07 – which uses MySQL v5.6.38.
At some point a future release of MAMP will no doubt use a version of MySQL that doesn’t include the PASSWORD() function. When this happens – as of MySQL v5.7.6 – the command to reset the root password is:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';