Changing the MySQL Root User Password in MAMP

C

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 changing a known password for the root user. If you’ve forgotten it please refer to Resetting MAMP’s MySQL Root User Password.

These instructions are for the free version of MAMP not MAMP Pro. They are applicable to MAMP versions 2.x, 3.x, 4.x and 5.x but be aware of the slight difference in the changes required.

 

For MAMP versions 2.x, 3.x, 4.x and 5.x

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:

Dummy Content
/Applications/MAMP/Library/bin/mysqladmin -u root -p password NEWPASSWORD

 

 

You’ll be prompted for the current root password:

Enter password:CURRENTPASSWORD

 

 

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

 

 

File: /Applications/MAMP/bin/phpMyAdmin/config.inc.php

$cfg['Servers'][$i]['user']             ='root';            // MySQL user
$cfg['Servers'][$i]['password']         ='NEWPASSWORD';     // MySQL password (only needed
                                                            // with 'config' auth_type)

 

 

As an alternative to updating these files manually I’ve written a simple Bash script that runs in Terminal and updates the files with the new password. Instructions can be found in the repository’s README.md file.

If you’re using MAMP 3.x, 4.x or 5.x stop and restart MAMP’s MySQL server to complete the password change. If you’re using MAMP 2.x continue reading for some additional changes.

 

For MAMP version 2.x only

File: /Applications/MAMP/bin/mamp/index.php

$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 3.x, 4.x or 5.x but for MAMP 2.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>
					

 

 

Upgrading MAMP

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.

About the author

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.

61 responses

60 Comments

  • Dear Sir,

    im using MAMP Version 4.2 and i have the same Issue , but the Problem is, that i dont find mysqladmin or mysqlcheck or mysql_upgrade etc. in the bin directory, they are all an exe file . Do you have any hints for me?

    Thank you so much in advance

    • Sounds like you’re using the Windows version of MAMP, but these instructions are for the Mac version. Unfortunately, I’ve no experience of using MAMP under Windows.

      Regards, Steve.

  • Maaaaaaaaannnnn…my god thanks *so* much for this! I don’t understand, at all, why the documentation isn’t there for this. You’re a lifesaver, Steve! Muchos gracias.

  • I upgraded to MAMP version 4.2.1 and began to get an alert on launch “Checking the MySQL databases failed.” If I dismiss the alert everything seems to work fine. However I would like to fix MAMP so the alert doesn’t display anymore.

    I did not change my password and when developing locally, using “root” keeps things simple so I would like to keep the default password as is.

    My question is, will your above method allow me to reset the default password? In other words, I want to reset “root” to “root.”

  • 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.

  • Hi, Steve!

    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!

    Chima.

  • 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(
      “$host:$port”,
      $user,
      $password
      );
      $db_selected = mysql_select_db(
      $db,
      $link
      );

      • 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?

        • @dustyhope

          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.

          Regards, Steve.

  • Steve,

    You’re the man! I … like an idiot changed my root user password and immediately forgot it. I have tried several other fixes without success. Your solution worked perfectly and I am good to go once again.

    You sir, are bookmarked!

    Thanks for the fix!
    Brad

  • i tried to disable the password for root but it will promt the error message, i tried to change the password by just deleting the old password and followed your instructions but it still doesnt work. can you help me with this? thank you

    • @AR,

      I’ve not tried using MAMP without a password for the root user and I don’t know whether MAMP will allow this or not. I’d suggest resetting the root user password.

      Regards, Steve.

  • 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.

  • 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)

    J.Singh

  • 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)

    Jas Singh.

    • @JAS

      …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.

      Regards, Steve

  • Hi Steve,
    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!
    Bern

  • 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!

  • 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.

    • @Ime

      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:

      /Applications/MAMP/Library/bin/mysql
      

      You should see the MySQL command line prompt mysql>

      Type:

      UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root';
      

      Press enter, then type:

      FLUSH PRIVILEGES
      

      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
      

      Regards, Steve

  • 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

  • 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!!

  • 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.

    • Hi Tam,

      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.

      Regards, Steve.

  • Hi Steve,
    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

  • 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!

1 Pingback

Steve

Recent Comments

Recent Posts