Changing the MySQL Root User Password in MAMP

Steve February 29 Local Server , , with 53 and 0
Home/Local Server/Changing the MySQL Root User Password in MAMP

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 both MAMP v2.x, v3.x and v4.x but be aware of the slight difference in the changes required.

For MAMP versions 2.x, 3.x and 4.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:

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

 

 

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.

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

 

 

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.

53 Responses

53 Comments

  • John Prusinski
    on August 11th, 2016 at 00:37
    Reply

    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.

  • Chima
    on May 7th, 2016 at 19:41
    Reply

    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.

    • Author
      Steve
      on May 8th, 2016 at 09:47
      Reply

      @Chima,

      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

      Regards, Steve.

      • Chima
        on May 10th, 2016 at 10:25
        Reply

        Oops!

        Looks like the link’s missing a URL, Steve.

  • dustyhope
    on March 22nd, 2016 at 03:30
    Reply

    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.

    • dustyhope
      on March 22nd, 2016 at 04:07
      Reply

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

      • dustyhope
        on March 22nd, 2016 at 05:07
        Reply

        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?

        • Author
          Steve
          on March 23rd, 2016 at 07:33
          Reply

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

  • Kabkee
    on December 9th, 2015 at 15:16
    Reply

    That’s IT!!!!! Thank you so much.

  • Brad
    on March 26th, 2015 at 01:32
    Reply

    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

  • AR
    on February 27th, 2015 at 15:54
    Reply

    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

    • Author
      Steve
      on February 27th, 2015 at 16:10
      Reply

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

  • Arun
    on July 27th, 2014 at 21:47
    Reply

    That worked! Thanks a lot buddy!

  • erik
    on April 23rd, 2014 at 02:08
    Reply

    Man, you are fantastic. You are the first and only that explained this stuff correctly. Got it working again.

  • Moni
    on March 18th, 2014 at 23:13
    Reply

    Thank you so much for this! Your solution is the only one that worked for me. You’re completely brilliant.

  • Sergio Ianez
    on January 23rd, 2014 at 23:18
    Reply

    Thanks Steve! It was pretty helpful!

  • Michael Park
    on January 7th, 2014 at 18:26
    Reply

    Excellent instructions, thank you for sharing Steve.

    • Author
      Steve
      on January 8th, 2014 at 06:53
      Reply

      You’re welcome Michael.

  • Zach Brown
    on January 2nd, 2014 at 02:50
    Reply

    Thanks Much! Was getting very frustrated with this, followed your guide and it worked like a charm!

  • RR
    on November 27th, 2013 at 04:42
    Reply

    Thank you;-). it worked like a charm…

  • Jas Singh
    on November 15th, 2013 at 02:47
    Reply

    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

    • bachiri
      on November 18th, 2013 at 02:21
      Reply

      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

      • Author
        Steve
        on November 18th, 2013 at 12:28
        Reply

        @bachiri,

        Here are instructions on setting an empty root password. I don’t know how this will effect MAMP though as I’ve never tried it.

        Regards, Steve.

    • Author
      Steve
      on November 15th, 2013 at 06:53
      Reply

      @Jas,

      You’re welcome. Glad you got it working.

      Reagrds, Steve

  • JAS SINGH
    on November 14th, 2013 at 12:54
    Reply

    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.

    • Author
      Steve
      on November 14th, 2013 at 15:51
      Reply

      @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

  • Bern Ruelas
    on November 12th, 2013 at 06:51
    Reply

    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

    • Author
      Steve
      on November 12th, 2013 at 08:49
      Reply

      @Bern

      Glad you found it helpful. Have noted your suggestion. Thanks.

      Regards, Steve.

  • Paul
    on October 25th, 2013 at 23:39
    Reply

    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!

    • Author
      Steve
      on October 26th, 2013 at 06:23
      Reply

      You’re welcome Paul.

  • Clotilde
    on September 3rd, 2013 at 22:24
    Reply

    Thank you so much!

    I keep this page preciously in my favorites folder!!

  • Atanas
    on August 27th, 2013 at 01:15
    Reply

    Thank you !

  • Waco
    on May 9th, 2013 at 08:53
    Reply

    Thanks! You saved my day!

  • Ramki
    on April 28th, 2013 at 15:23
    Reply

    Perfect, very very useful. Worked like a charm. Thanks!!

  • Ime Prezime
    on April 21st, 2013 at 08:42
    Reply

    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.

    • Author
      Steve
      on April 21st, 2013 at 10:50
      Reply

      @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

      • Peter
        on December 6th, 2013 at 01:32
        Reply

        Steve, your solution is the only one on the Internet that worked for me. Thanks so much in helping out.

        • Author
          Steve
          on December 6th, 2013 at 16:08
          Reply

          @Peter,

          Glad you found it helpful.

          Regards, Steve.

  • Ben
    on March 25th, 2013 at 12:49
    Reply

    See the link above (subatrout.com) regarding changing the passwords in the scripts /Applications/MAMP/bin/*sh
    This will get around startup errors.

  • sebastian
    on February 4th, 2013 at 13:29
    Reply

    I’m !#*$%! noob on these! After all the steps, I get mysql working typing on terminal “killall -9 mysqld” thank you

  • Ben
    on December 14th, 2012 at 13:25
    Reply

    Thanks so much for this — this worked perfectly!

  • Gregory Lee Newsome
    on November 5th, 2012 at 04:03
    Reply

    Worked perfectly – thank you so much!

    • Author
      Steve
      on November 5th, 2012 at 14:20
      Reply

      You’re welcome Gregory.

  • DJ
    on July 30th, 2012 at 22:45
    Reply

    Thanks! That worked perfectly!

    • Author
      Steve
      on July 31st, 2012 at 07:21
      Reply

      Glad you found it useful DJ.

      Regards, Steve.

  • tam
    on April 17th, 2012 at 21:56
    Reply

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

    • Author
      Steve
      on April 17th, 2012 at 22:23
      Reply

      Glad you’ve got it working Tam.

      Regards, Steve.

  • tam
    on April 17th, 2012 at 06:02
    Reply

    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.

    • Author
      Steve
      on April 17th, 2012 at 13:52
      Reply

      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.

  • subrat
    on March 21st, 2012 at 11:45
    Reply

    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

  • Matt
    on March 9th, 2012 at 05:26
    Reply

    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!

    • Author
      Steve
      on March 9th, 2012 at 07:12
      Reply

      You’re welcome Matt.

1 Pingback

Add comment

©Tech Otaku 2009 - 2017