Having recently changed my local testing server environment from XAMPP to MAMP v2.0.5 I wanted to change the password for the MySQL root user. By default it’s set to root.
Changing the MySQL password for the root user was straightforward enough, but locating and editing the files to reflect the new password was a different story. Failure to update all the necessary files results in MAMP reporting the following error:
/Applications/MAMP/Library/bin/mysqlcheck: Got error: 1045: Access denied for user ‘root’@’localhost’ (using password: YES) when trying to connect
Information on MAMP’s own site appeared incomplete and other documentation I found — while helpful — was for versions of MAMP prior to version 2.
These instructions are for the free version of MAMP not MAMP Pro. They are applicable to both MAMP v2.x, v3.x and v4.x but be aware of the slight difference in the changes required.
To change the MySQL password for root ensure that MAMP’s MySQL server is running then open Terminal and type the following, replacing NEWPASSWORD with the password of your choice:
/Applications/MAMP/Library/bin/mysqladmin -u root -p password NEWPASSWORD
You’ll be prompted for the current root password:
Next, all the occurrences of the old password root need to be changed to the new password NEWPASSWORD in the following files. For files marked * an easy way to locate the old password is to search for the string -proot where -p is the password option and root is the old password.
File: /Applications/MAMP/bin/checkMysql.sh *
# /bin/sh /Applications/MAMP/Library/bin/mysqlcheck --all-databases --check --check-upgrade -u root -pNEWPASSWORD --socket=/Applications/MAMP/tmp/mysql/mysql.sock
File: /Applications/MAMP/bin/quickCheckMysqlUpgrade.sh *
# /bin/sh /Applications/MAMP/Library/bin/mysqlcheck --quick --check-upgrade -u root -pNEWPASSWORD --socket=/Applications/MAMP/tmp/mysql/mysql.sock mysql
File: /Applications/MAMP/bin/repairMysql.sh *
# /bin/sh /Applications/MAMP/Library/bin/mysqlcheck --all-databases --repair -u root -pNEWPASSWORD --socket=/Applications/MAMP/tmp/mysql/mysql.sock
File: /Applications/MAMP/bin/stopMysql.sh *
# /bin/sh /Applications/MAMP/Library/bin/mysqladmin -u root -pNEWPASSWORD --socket=/Applications/MAMP/tmp/mysql/mysql.sock shutdown
File: /Applications/MAMP/bin/upgradeMysql.sh *
# /bin/sh /Applications/MAMP/Library/bin/mysql_upgrade -u root -pNEWPASSWORD --socket=/Applications/MAMP/tmp/mysql/mysql.sock --force
$cfg['Servers'][$i]['user'] ='root'; // MySQL user $cfg['Servers'][$i]['password'] ='NEWPASSWORD'; // MySQL password (only needed // with 'config' auth_type)
If you’re using MAMP v3.x or v4.x stop and restart MAMP’s MySQL server to complete the password change. If you’re using MAMP v2.x continue reading for some additional changes.
$port = '3306'; $link = @mysql_connect(':/Applications/MAMP/tmp/mysql/mysql.sock', 'root', 'NEWPASSWORD');
Finally, stop and restart MAMP’s MySQL server to complete the password change.
Purely for cosmetic purposes you may also want to update MAMP’s start page to reflect the changed password. This file does not exist in MAMP v3.x or v4.x, but for MAMP v2.x the English version of this file is /Applications/MAMP/bin/mamp/English/index.php:
<table class="mysql"> <tr> <th>Host</th> <td>localhost</td> </tr> <tr> <th>Port</th> <td>3306</td> </tr> <tr> <th>User</th> <td>root</td> </tr> <tr> <th>Password</th> <td>NEWPASSWORD</td> </tr> </table> <h3>Example:</h3> <pre>$link = mysql_connect('localhost', 'root', 'NEWPASSWORD');</pre> <p>or you can connect using an UNIX Socket:</p> <table class="mysql"> <tr> <th>Socket</th> <td>/Applications/MAMP/tmp/mysql/mysql.sock</td> </tr> <tr> <th>User</th> <td>root</td> </tr> <tr> <th>Password</th> <td>NEWPASSWORD</td> </tr> </table> <h3>Example:</h3> <pre> $link = mysql_connect( ':/Applications/MAMP/tmp/mysql/mysql.sock', 'root', 'NEWPASSWORD' ); </pre>
When upgrading, the current MAMP folder in the /Applications directory is renamed MAMP_yyyy-mm-dd_hh-mm-ss before a new MAMP folder containing the upgrade is created. MAMP also has the foresight to retain the root user password, but unfortunately uses new versions of all the above files containing – once again – the root user password of root. This necessitates either updating the files again or copying the appropriate files from the MAMP_yyyy-mm-dd_hh-mm-ss folder.
A native Brit exiled in Japan, Steve spends too much of his time struggling with the Japanese language, dreaming of Fish & Chips and writing the occasional blog post he hopes others will find helpful.
Thanks man. You’re a big help.
I had changed my MAMP/MySQL password from ‘root’ to ‘(blank)’ as I thought it would be handy while working on some college assignments as they had XAMPP settings for ‘localhost’ with ‘(no password)’.
I knew something was wrong when I saw a notice from MAMP that databases need to be updated (hello world of 7.0) but it failed to update the databases.
MySQL server was running fine, I can access MAMP’s MysQL from terminal too. MySQLWorkbench was working fine and it shows all my schemas/tables.
But, couldn’t open PHPMyAdmin from the MAMP start page though. DOH! I was going to use PHPMyAdmin to create some new Users because waaaay simpler than Workbench’s version (probably need a hard drink to understand that one).
Spent a couple of hours searching and came across this post.
Thanks again, from halfway around the world in Ireland.
I spent hours looking for a solution to this issue, and trying all the strategies I could find without success… until I found this page. Thanks so much for the clear (and thorough!) explanation… it worked like a charm, and saved me from pulling my few remaining hairs out of my head.
Your article outlines the only complete and straightforward procedure — to the letter — in all of the Web for changing MySQL ‘root’ password in MAMP, and I thank you for it.
The MAMP development team is rather cryptic on the subject, for obvious reasons. And who can blame them? We all have to make a living somehow.
Ironically, a flawless MAMP ‘proving ground’ is arguably the single most powerful sales pitch for MAMP Pro, with no fewer than four compelling reasons to purchase the upgrade:
1. Enhanced GUI configuration, including — you guessed it — changing MySQL ‘root’ password.
2. Unlimited virtual hosts, with additional support for older versions of PHP.
3. Out-of-the-box eMail functionality.
4. Support for dynDNS — great for collaboration and distance-review.
Most Web developers and designers want a hassle-free localhost environment with the broadest possible feature set — precisely the priced turf of MAMP Pro — that enables them to hone their craft. Sadly, anyone with no prior knowledge of the MAMP pedigree who stumbles on changing MySQL ‘root’ password in the free sibling foundation stack — through no fault of his or hers — is unlikely to commit to a $59 MAMP Pro upgrade and may even abandon the brand altogether. it’s hard to see how willful misdirection by documentation trickery can possibly help MAMP Pro sales.
In my case, the inability to successfully change MySQL ‘root’ password (following the developer’s ‘incomplete’ documentation) quickly mushroomed into outsized frustration which endlessly gnawed at me in sobering quandary, so much so that I came uncomfortably close to giving up on the MAMP brand altogether, eager to move on, perhaps conveniently dismissing the stack as unreliable, or inconsistent at best.
And then… Tech Otaku to the rescue!
I couldn’t be happier that I persisted in my quest for sanity until I found you. Thanks to you, I now have a fully operational MAMP. With the password-related database errors now behind me, I can finally see MAMP for the superior stack it truly is. Needless to say, my confidence in the brand also makes it a no-brainer to purchase MAMP Pro, if only to support continued development of the stack. One has to wonder how many would-be MAMP Pro prospects never make it this far.
Thanks again for this invaluable resource, and best wishes for continued success always!
Thank you for your eloquent thoughts. I’m glad you found this post helpful. I’ve always considered the main reason to go Pro – as you mentioned – is being able to use virtual hosts, but that too can be achieved with the free version: Configuring Virtual Hosts in MAMP on Mac OS X
I totally goofed up reinstalled MAMP and now nothing works. I have followed all your directions. changed the password in the terminal. then I change all the files to new password. when mamp comes up it says — /Applications/MAMP/Library/bin/mysqlcheck: Got error: 1045: Access denied for user ‘root’@’localhost’ (using password: YES) when trying to connect — still. the thing is I havent even files up to mysql – it wont let me in to do it!! any ideas! ahhhhh.
I have change password. and have double checked all the files. where you say NEWPASSWORD – in changing all those files – I actually put in the newpassword, correct. now MAMP opens but says : Notice: Undefined index: password in /Applications/MAMP/bin/mamp/index.php on line 269
$db = ‘inventory’;
$host = ‘localhost’;
$port = 3306;
$link = mysql_connect(
$db_selected = mysql_select_db(
I seem to have done it. though I am not sure how — but I got MAMP working again with wordpress and mysql. how can I double check using mac terminal that the mamp mysql password is indded changed ?? I just want to confirm its all gone thru — do you suggest I download mysql to my machine — too?
Sorry to hear you were having problems. You don’t need to download MySQL. If the green indicator is on in MAMP denoting the MySQL server is running and your WordPress install is able to access its MySQL database using the password set in WordPress’s wp_config.php file then I’d say it’s working OK.
That’s IT!!!!! Thank you so much.
That worked! Thanks a lot buddy!
Man, you are fantastic. You are the first and only that explained this stuff correctly. Got it working again.
Thank you so much for this! Your solution is the only one that worked for me. You’re completely brilliant.
Thanks Steve! It was pretty helpful!
You’re welcome Michael.
Thanks Much! Was getting very frustrated with this, followed your guide and it worked like a charm!
Thank you;-). it worked like a charm…
Thank you !!!! It took some time to get my head around what I had done to then solve the problem. Your directions are simple and easy to understand, cheers (Y)
hii thanks for your help, i want to change my password from root to nothing please help because time to time i want to megrite my projet to windows os
You’re welcome. Glad you got it working.
Your guide looks exactly like what I’v been searching the web for, but there is one problem. When in terminal I am unable to type or paste a password :/ non of my keys input anything.
(I may be overlooking something as I am not familiar with using terminal or mysql)
…When in terminal I am unable to type or paste a password :/ non of my keys input anything…
Do you mean when you try to enter the NEWPASSWORD or the CURRENTPASSWORD? If it’s the latter, then this is expected. As you enter the CURRENTPASSWORD at the Enter password: prompt, the cursor will not move nor will any characters you type be displayed. If it’s the former, or both, I’ve not heard of that before.
Just need to say THANKS! This was a 6 hours quest to get back to my database.
Works like a charm. I had completely misread this statement above:
“Next, all the occurrences of the old password root need to be changed to the new password NEWPASSWORD in the following files. ”
Reading it now makes sense…however as a suggestion, if it had read:
“Edit all of the following files and change…” I would have gotten it immediately.
Thanks for the post!
Glad you found it helpful. Have noted your suggestion. Thanks.
Steve, thanks a bunch for this. I had been trying to use similar instructions for MAMP 1.x but they didn’t have the instructions for the MAMP/bin/mamp/index.php file. You saved me! I’ll be sure to add this to my bookmarks for future reference!
You’re welcome Paul.
Thank you so much!
I keep this page preciously in my favorites folder!!
Perfect, very very useful. Worked like a charm. Thanks!!
I did everything you specified, that is i changed every single file of the ones given above exactly how you said to change it.
I also did the killall mysqld and nothing changed. I restarded my server couple of times and I still get
Error: Could not connect to MySQL server!
The mamp gives me this error:
/Applications/MAMP/Library/bin/mysqlcheck: Got error: 1045: Access denied for user ‘root’@’localhost’ (using password: YES) when trying to connect
The only thing different from what you did is that i didn’t change the password using the terminal but i changed the user info in the users part of the phpmyadmin control panel and put a new password there. Now when i try to change password, when it asks for my current password neither root nor my CHANGEDPASSWORD word which is very confusing.
I really don’t know how to fix this since I changed every file you said and made sure multiple times.
Sorry to hear you’re having problems. I have two suggestions.
The first and simplest is to quit MAMP and drag the /Applications/MAMP folder to the Desktop and re-install MAMP. You’ll have a fresh install of MAMP and also the original MAMP files on the Desktop should you need to restore any files.
The second is a little more involved and requires use of the Terminal, but allows you to reset the root password without the need for the current root password.
First, quit MAMP or simply stop MAMP’s MySQL server running.
Open Terminal and type (copy & paste):
/Applications/MAMP/Library/bin/mysqld_safe --skip-grant-tables --skip-networking --port=8889 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --lower_case_table_names=0 --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid &
You’ll need to press the enter key twice.
To use the MySQL command line type:
You should see the MySQL command line prompt mysql>
UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root';
Press enter, then type:
Press enter, then to quit the MySQL command line type \q:
You should be returned to the Terminal prompt.
Stop MySQL by typing:
/Applications/MAMP/Library/bin/mysqladmin --socket=/Applications/MAMP/tmp/mysql/mysql.sock shutdown
Glad you found it helpful.
See the link above (subatrout.com) regarding changing the passwords in the scripts /Applications/MAMP/bin/*sh
This will get around startup errors.
I’m !#*$%! noob on these! After all the steps, I get mysql working typing on terminal “killall -9 mysqld” thank you
Thanks so much for this — this worked perfectly!
You’re welcome Gregory.
Glad you found it useful DJ.
yay!! Just knowing it works suffices 🙂 I used killall mysqld from the terminal and then restarted. Awesome!! The only thing now is that the start page comes up blank but has the menu bar in place so I can still go in to the phpMYAdmin (although I did follow your instructions to change the pw for the start page). Gosh, I had broken MAMP a bizzilione times in the past. Your instructions are very clear and COMPLETE. I did it JUST once. Thanks much!!
Glad you’ve got it working Tam.
I followed the instructions precisely but I am now getting this message:
‘”Error: Could not connect to MySQL server!”
What could I have missed? Please help.
Difficult to know what to suggest: Is MAMP’s MySQL server starting? Do you get the error message when trying to open MAMP’s start page? Have you looked in /Applications/MAMP/logs/mysql_error_log.err for any tell-tale error messages? You may want to try issuing the command killall mysqld from Terminal which will terminate any errant MySQL processes running and then restarting MAMP’s servers.
Thanks for the article. It was really helpful. Just a quick question. Which WP plugin is used to write code snippets on the article?
Thanks for this! I keep breaking MAMP because I want to use something other than root/root for mySQL. Crazy how many places they hard code this!
You’re welcome Matt.
[…] site. However I found out another blog post which has described how to fix it in detail here. However, for changing the root password the following command did not […]