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 When quitting MAMP: Stop Servers 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 ↵:
/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 ↵ 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 ↵, then type the following replacing NewPassword with the password of your choice (see 1 below if you’re using MAMP 4.5 or earlier):
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
Press ↵, then type:
Press ↵. 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 ↵.
/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 5.7.6 the PASSWORD() function has been deprecated. This affects versions of MAMP since 5.0 – released on 2018-07-31 – which shipped with MySQL 5.7.21. However, if you’re using MAMP 4.5 – which shipped with MySQL 5.6.38 – or earlier, the command to reset the root password is:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('NewPassword');
MAMP Release Notes