I originally posted this in the MAMP HowTo, but didn't get a response within a week -- probably few people watch that space. Apologies for the cross-post.

That page says:

Also, remember that the default MySQL username/password is root/root! For security purposes, it's always best to change this.

I can't seem to do this. The directions on MAMP's FAQ tell us to:

Open the terminal and type the following:

/Applications/MAMP/Library/bin/mysqladmin -u root -p password

Instead of use the new password you want.

But this doesn't work for me. Here's what I get:

$ /Applications/MAMP/Library/bin/mysqladmin -u root -p password newpasswordhere

Enter password: [newpasswordhere]

/Applications/MAMP/Library/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)'

Check that mysqld is running and that the socket: '/var/mysql/mysql.sock' exists!

I also tried it under sudo, with no luck. Any help? Thanks,

---
Tom Geller * San Francisco
SaveMyHomeBook.com (Drupal!) * TomGeller.com (not Drupal)

Comments

gollyg’s picture

Have you had the server up and running yet, or is this a completely new install. I had an issue with setting up MAMP relating to a previous install of mysql which gave the same message. But it wouldnt start at all.

The fix i found was to do a full search on my system for the file mysql.sock. This showed up an old version of the file that for some reason was preventing mysql from being able to create this file. You could also try a sudo killall mysqld at the terminal (do a google search on this because that is just from memory and the syntax is probably different).

But if you have already had the server up, perhaps you just need to shut it down before you attempt to change the password? The socket file is actually created each time mysql startsup.

tgeller’s picture

Thanks for your reply, and sorry it's taken me a while to answer. The server is just my local machine: This is for staging, not production.

I did "updatedb" and then "locate mysql.sock". That led to the following exchange:

$ locate mysql.sock

/private/var/mysql/mysql.sock

$ more /private/var/mysql/mysql.sock

/private/var/mysql/mysql.sock: No such file or directory

$ cd /private/var/mysql/

$ ls -al

lrwxr-xr-x 1 root wheel 15 Mar 25 16:53 mysql.sock -> /tmp/mysql.sock

$ more /tmp/mysql.sock

/tmp/mysql.sock: No such file or directory

$

So the file appears to exist... but not exist. Any ideas?

---
Tom Geller * San Francisco
SaveMyHomeBook.com (Drupal!) * TomGeller.com (not Drupal)

---
Tom Geller * tomgeller.com * Oberlin, Ohio
See my lynda.com videos about Drupal

gollyg’s picture

The presence of that file could be the issue. Have you had another install of mysql on your machine? Be sure that personal webserver is disabled (in the network preferences). How to delete is - cant actually remember but perhaps you need to be sudo? I am a bit beyond my knowledge of mysql here, but i know that i struggled with this for quite some time before discovering the issue.

Another common cause of this is permissions - the file cant be written to the correct location, but this should not be in issue in MAMP. But you could check.

There are a few posts on the web about various approaches to fixing this - try googling the error message.

Hope you figure it out, i know how frustrating these issues can be.

tgeller’s picture

Thanks for the ideas. I tried issuing the above commands using "sudo", to no avail.

I *have* had another instance of MySQL running on this machine in the past, and agree that that could be what's messing things up. But I don't know what to do about it. (I checked, and Personal Web Sharing is off.)

I'll Google the error. But in the meantime if any ideas occur to you, or anyone else reading this, I'd love to hear them. Thanks again!

---
Tom Geller * San Francisco
SaveMyHomeBook.com (Drupal!) * TomGeller.com (not Drupal)

---
Tom Geller * tomgeller.com * Oberlin, Ohio
See my lynda.com videos about Drupal

tgeller’s picture

The problem was that MAMP was using an entirely different mysql.sock file, located at /Applications/MAMP/tmp/mysql/mysql.sock. So to fix it:

1. Stop MAMP. (This step might be unnecessary... but why take chances?)

2. $ sudo rm /var/mysql/mysql.sock. This removes the incorrectly symlinked mysql.sock file.

3. Start MAMP. (This step might also be unnecessary, but the target mysql.sock file doesn't exist unless MySQL is running.)

4. sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock. This sets up the symlink correctly.

5. Restart MAMP.

Now my backup script seems not to have the "mysql.sock" error. I haven't tried changing the password yet, but assume that'll work as well -- I'll post here if not.

If anyone would care to comment on whether steps #1 & #3 are necessary, that'll save future generations a few seconds. :)

Thanks again for all your help!

---
Tom Geller * San Francisco
SaveMyHomeBook.com (Drupal!) * TomGeller.com (not Drupal)

---
Tom Geller * tomgeller.com * Oberlin, Ohio
See my lynda.com videos about Drupal

iamnth’s picture

I encountered a problem that /var/mysql/mysql.sock doesn't exist! Yet I found a solution to this.

Create the /var/mysql directory (sudo mkdir /var/mysql)

tgeller’s picture

Here's what happens:

$ /Applications/MAMP/Library/bin/mysqladmin -u root -p newpassword

Enter password:

/Applications/MAMP/Library/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/mysql/mysql.sock' exists!

$ ls -al /var/mysql/
lrwxr-xr-x 1 root wheel 39 Jun 25 14:11 mysql.sock -> /Applications/MAMP/tmp/mysql/mysql.sock
$

I'm stumped! It appears that the socket is installed there correctly.

Here's a simple question: How can I "check that mysqld is running"?

Thanks,

---
Tom Geller * San Francisco
SaveMyHomeBook.com (Drupal!) * TomGeller.com (not Drupal)

---
Tom Geller * tomgeller.com * Oberlin, Ohio
See my lynda.com videos about Drupal

unruthless’s picture

Hi Tom,

No need to use sudo. MAMP's documentation around this is poorly worded.

Here's what you need to enter at the command line, where [NEWPASSWORD] is the password you'd like, and [OLDPASSWORD] is the current password (so, if you've never changed the MySQL password before, [OLDPASSWORD] is root):

$ /Applications/MAMP/Library/bin/mysqladmin -u root -p password [NEWPASSWORD]
Enter password: [OLDPASSWORD]

Hope this works for you!

tgeller’s picture

So my error was in entering the new password twice, rather than the old password when prompted! It seems to work now.

Thanks for answering a 16-month-old question that still gnawed at me. :)

---
Tom Geller * tomgeller.com * Oberlin, Ohio
See my lynda.com videos about Drupal

rusloc’s picture

When prompted "Enter password:" I must enter "root"?
It's a brand new install of MAMP 1.8.3 on Snow Leopard 10.6.1, and I am having exactly the same problem as Tom 16 months ago.
I followed your CLEARER (thank you) instructions, but the result is the same.

/Applications/MAMP/Library/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/mysql/mysql.sock' exists!

tgeller’s picture

See Subject line. :)

---
Tom Geller * tomgeller.com * Oberlin, Ohio
See my lynda.com videos about Drupal

Latestnewbie’s picture

[tentatively]

I found this video helped me with this problem

http://www.youtube.com/watch?v=X4FvTPkRUoI