14

I'm running MAMP.
It has been working fine up until yesterday. I haven't been able to find anything that helps so far. But here is my problem:

As the title states I'm receiving the following error:

error #2002 "Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)"

which, I have noticed, seems to be a pretty common error when I search for it.

Anyway, When I cd to tmp/mysql and ls -laxo the only thing that shows up besides the ./ and ../ directories is .dummy (I have no idea what that is, but I have a hunch it's not the source of my problem).

That is where the mysql.sock file is suppose to be located. Does anyone know of a way to fix this. Maybe I need to create the mysql.sock file but I wouldn't know what to put in it.

Jean
  • 7,327
  • 6
  • 41
  • 58
Brandon Beeler
  • 141
  • 1
  • 1
  • 6
  • 2
    It's a been a while since I had this issue. But I believed I was able to fix this by running the command "killall mysqld" in the terminal. Hope that is somewhat helpful. – Brandon Beeler Apr 16 '13 at 20:54
  • @BrandonBeeler: Thank you for coming back to post your fix. It worked for me when nothing else did :) You may want to post it as an answer and select it as the answer. – Ivan Durst Jun 11 '15 at 18:10

6 Answers6

29

Test

If you attempt to start MySQL using the full path it should work

/Applications/MAMP/Library/bin/mysql -u root -p

Fix

If that works, then you can set it to work normally by running

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

Resolution

Now MySQL should work normally

mysql -u root -p
davidcondrey
  • 29,530
  • 14
  • 105
  • 129
  • 7
    what happens if the 'Test' fails? I still get the same error – Mazzone Apr 03 '15 at 04:51
  • You have another parameter that requires this answer to work... This doesn't like look a very valuable answer. – ReBa Sep 03 '16 at 08:26
  • For those of you using XAMPP on OSX, @davidcondrey is still correct but the ```PATH``` differs slightly: ```ln -sf /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock /tmp/mysql.sock``` and it should fire successfully. – eulerworks Nov 02 '16 at 17:03
  • u save my day :D tks! – LegoBoy Apr 13 '18 at 08:18
7

I know this is late, but if ever someone is searching this (as I was tonight, but I found the solution), here's what worked for me:

I opened MAMP and had to click "USE default Apache and MySQL ports". (80 and 3306 instead of 8888 and 8889). That seemed to fix the issue.

Tur1ng
  • 506
  • 4
  • 18
4

Silly solution... But in my case, I didnt start the mysql server. So, look that also!

ValRob
  • 1,797
  • 4
  • 26
  • 33
1

Mysql server has not started.

mysqld stop
mysql.server start
Prakhar Agarwal
  • 2,310
  • 23
  • 30
1

If you'd rather avoid changing ports through MAMP or options in my.cnf file, it might be useful to try forcing a TCP connection via the following on the command line:

/Applications/MAMP/Library/bin/mysql -h 127.0.0.1 -P 8889 -u root

Remembering to set the port is important if it's anything other than the mysql default of 3306.

The -P parameter allows you to set the port.

MAMP's default port is 8889, but you can verify what yours is set to easily via the MAMP WebStart page while MAMP is running:

http://localhost:8888/MAMP/

It'll look similar to this:

enter image description here

afilbert
  • 1,110
  • 1
  • 19
  • 21
0

I faced the same problem. When i start MAMP separately, then the problem gone. And issuing following command worked fine.

mysql -u root -p
  • This could also help: https://stackoverflow.com/questions/9335403/access-mamps-mysql-from-terminal – caramba Mar 09 '19 at 00:23