Mac OS X: Trouble with MAMP MySQL

Stefan - 9. Juli 2007

MAMP is for Mac what XAMPP is for windows: A very easy-to-use, but Mac-like web development solution. Everything worked out-of-the box as it should – until I tried to install WordPress on my MacBook. I got a database connection error very early during the WordPress installation process.

So I tried to talk to the mysql server with the mysql command line tool and got this error message:
macbook:~ sf$ /Applications/MAMP/Library/bin/mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

This was strange as the mysql server was indeed running; I could verify this by an ps command. Futhermore phpMyAdmin, as provided by MAMP, worked flawlessly. Doing some Google research told me that the problem was connected with the location of mysql.sock.

Running ps -awwx | grep mysql showed, that mysqld had been started by MAMP with the option --socket=/Applications/MAMP/tmp/mysql/mysql.sock, whereas the mysql tool and WordPress assume the socket file here: /tmp/mysql.sock.

With this information the solution is easy:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
This creates a symbolic link from the location expected by mysql and wordpress to the location where the socket file resides. Now I can access my mysql server with the mysql command line tool and my local WordPress installation can also talk to the database.

Abgelegt in: Apple MacWeb 2.0

86 Kommentare:

[…] Mac OS X: Trouble with MAMP MySQLMAMP is for Mac what XAMPP is for windows: A very easy-to-use, but Mac-like web development solution. Everything worked out-of-the box as it should – until I tried to install WordPress on my MacBook. I got a database connection error very early during… […]

[…] socks, sockets and sudo’s – something i really don’t care or want to learn. Thankfully, the fix was simple, but virtually impossible to guess or work out the solution for oneself. I thought using […]

thanks for the help Stefan – this is really helpful!

Can anyone tell me how the above fix can be remembered after each re-boot? at the moment i have to re-run the sudo command every time i start up the OS. Any help, or pointers greatly appreciated!

Hi, I’m very interested about this topic.
I’m a new „Mac-User“ and I need to use my laptop as a local server for php pages.
I have installed MAMP 1.7: everything works fine using the following ports:
Apache: 8888
MySQL: 8889
The problem is when I try to create a new connection to the database using Dreamweaver CS3: if I use these parameters

Connection name: my_connection
Server: localhost:8888
Username: root
Password: root
Database: my_database

I have the following error message: „MySQL Error#: 2003 – Can’t connect to MySQL server on localhost (10061)“

All the parameters are correct: if I edit an test a php page like this:

everything is ok.

Why Dreamweaver can’t find MySQL connection?
I hope someone can help me.
Thank you in advance!

Genius! Thank you for working this problem out, it had been bothering me for a long time now.

Andrea,
you wrote your MySQL-Server listens on port 8889, but your Dreamweaver configuration tries to access the database server on port 8888 – which is the Apache server and not the MySQL server. Try to use localhost:8889.

Thank you!!! Now it works!!!
Andrea

Thanks for the tip!

I have tried the tip that you have provided, and it worked for a few of the accounts I manage on our Xserve, but not others. After creating the alias, it works for the root account, admin account, and one of the other user accounts, but all the others I have tested so far give me the old error I was receiving prior: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‚/var/mysql/mysql.sock‘ (13). Any suggestions?

Nevermind, I figured it out =) It was simply a mixture of cap-sensitivity between a few users and their database names, and file-permission settings on the /Applications/MAMP/tmp directory.

THANK YOU. 🙂

Helped me get to sleep tonight 🙂

Thanks for that. Seems to work when trying to use PEAR DB::connect – when the MAMP path directly wouldnt seem to… but I may just be crazy. 🙂

Thanks! This was an easy fix for me thanks to you.

Hi!

I tried this, but after running that line I assumed i could type:

mysql -h hostname etc…

but i get
-bash: mysql: command not found

Its probably amazingly simple, but im new to command line stuff on the Mac….

oh, its oK!

worked it out

Anyway, great fix, thanks!

i tried this on OS 10.5 but it still gives me the command not found error when i try and do a command line mysql command. any ideas?

Command not found is another kind of error. Did you try to invoke the mysql command with the complete path, e.g. /Applications/MAMP/Library/bin/mysql? If you just want to type mysql to start the command line tool, then you have to put your /Applications/MAMP/Library/bin directory into your default path.

[…] for me Stefan Fischerländer already found out how to solve […]

Thanks for interesting post

Thanks a lot ! I have been looking during two days on the net to find a solution to that very problem. I found your post… and it works !
Thanks
Nico

thanks for this – saved me hours of headache – particularly on data imports

I’ve run into an error trying to start MySql:

080826 09:38:04 mysqld started
080826 9:38:04 [ERROR] /Applications/MAMP/Library/libexec /mysqld: unknown option ‚–skip-federated‘

080826 09:38:04 mysqld ended

I don’t suppose anyone else has seen this?

Thanks!

Cliff

Easy solution:
When you configure connection in CocoaMySQL you have field called „Socket“. Now when you launch your MAMP start page it tells you to use UNIX socket: /Applications/MAMP/tmp/mysql/mysql.sock.
I pasted that socket into Socket field and it worked for me 🙂

better
/Applications/MAMP/Library/bin/mysql -uroot -p

than

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

Just to say Thanks!!!
=D

Thanks !
It saved me a day !

Thank you! Really helped me! 😀

Hi. I am using a macintosh and I am having troubles with my MAMP. I have just recently downloaded it and the mySQL light won’t come on when I go to start the servers. Apache is the only light that comes on. Please somebody help me!

Brilliant! Thanks for the great tip.

Suddenly after making changes in phpMyAdmin to some tables, I can no longer connect to MAMP start page. Now: Error: Could not connect to MySQL server! is what I see. I have tried to change MySql Port to 3306, back to 8889. Also, have attempted various terminal commands. Viewing my index.php (Applications/MAMP/bin/mamp) as i read in previous post has: $link = @mysql_connect(‚:/Applications/MAMP/tmp/mysql/mysql.sock‘, ‚root‘, ‚root‘);
Any thoughts? Maybe I changed username/password from phpMyAdmin? please help

okay,

so i deleted and reinstalled MAMP with success in launching start page. hope this helps.

Thanks a lot. This article saved me.

Cheers Dude,
you saved me from a massive headache. I had the issue while debugging php/mysql stuff with Aptana and MAMP.
The symbolic link saved it! I have the feeling that people trying to do the same with Zend Studio would love you too.
May be you’d like to post an update to this one.
By the way don’t listen to the loosers afraid by command line stuff, Mac OS is UNIX and it’s powerful 😉
Take care

Yes, the solution works! Thanks a lot!!!

Holy Shit! You just ended a two day, no holds barred throwdown between me and MAMP MySQL. Now I can finally get some work done. Thank You!

Thank you. Ran into the exact same problem with my MAMP installation. Now it works like a charm!

Hi – I’m new to this, fyi 😉 I opened terminal and executed:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

I assumed this was the way to fix the issue. But… it still doesn’t work. I’m running OS X 10.5.6. When I go to localhost:8888/wordpress/ I’m still getting „Error establishing a database connection“.

Did I do this incorrectly?

Thanks, works like a charm!
Just one thing:
Like Matt said at the moment i have to re-run the sudo command every time i start up the OS.
Is there a way how I could make this link permanent???
Thanks!

[…] in the default location, not wherever MAMP’s mySQL server is.  One solution, which I found here, is to put a symbolic link in the place where the library looks, which points to the real file in […]

Wow, thanks man! Solved my problem with Sequel Pro!

it seems i have to do this every time i fire up my mac. Is there a way to script this and have that script run on startup?
thanks
M

Guys, the mysql.sock file gets created when MAMP is started and is deleted when MAMP is stopped, that’s why it’s in /tmp/ – because it’s temporary. Creating an alias to this file works, but when the original is deleted, the alias is also removed.

A more permanent solution is to edit Mamp’s configuration files:

/Applications/MAMP/bin/startMysql.sh and
/Applications/MAMP/bin/stopMysql.sh

Just replace

socket=/Applications/MAMP/tmp/mysql/mysql.sock

with

socket=/tmp/mysql.sock

I have been trying to connect MySQL WorkBench (MWB) for Mac but not joy.

My local host is ok and can connect to DB in shell

1) tried the symlink solution but couldn’t connect with Error (61) that cannot connect

2) changed paths in MAMPs menu (changing those files in MAMP folder does noting) in File > Edit templates > MySQL my.conf, then php5.ini and so on -> didn’t work (after restart)

3) changed PATH/MAMP/bin/startMysql.sh and stopMysql.sh -> didn’t work when reloaded MAMP
IT ONLY WORKED when I killed processes and run those files manully in shell then was able to connect to MWB.

There used to be socket custom field in Mysql Browser that allowed to connect to socket in a different location. No such thing in MWB anymore. Why? don’t ask me – left feedback on MySQL forums asking for answers.

Things might stop working if you just change paths as described above because php.ini and many other scripts have this path to mysql.sock set to your MAMP folder. Just run in your MAMP this command to see how many:

egrep -alR –regexp=“/tmp/mysql/mysql.sock“ *

Thanks,this post just help me much.

I have MAMP running on a Mac Mini on my local network. I’ve set up an ODBC connection to the MySQL database using the MySQL ODBC 5.1 driver and it connects fine using the localhost/port 8889/Applications/MAMP/tmp/mysql/mysql.sock settings.

However, when I try to set up an ODBC connection from my MacBook to the same mysql db on that machine, I get an error: „Request Returned with SQL Error“ I’m guessing this has to do with how I’m referencing the port . . .

Any suggestions?

Thanls a lot for the symbolic link tip.
Simple, easy and effective.

SeeYa!

Djio

Thank you! Perfect! I’ve been stuck with this problem so many times!

thanx for that one!

I’m having the same problem as #39 Donald.
I can’t seem to connect to a clean wordpress install. I’ve double and triple checked the config file but I still get a ‚Error connecting to database‘ message.

I tried the solution listed here but I am still getting an error. Any ideas?

This fix just worked for me. Been trying to setup rails with a local installation of MySQL for a few days.

Thanks for the info!

Sweet. Problem solved. Thanks. I was all over the shop with that one. All the best. Neil

I’m have the same issue as Donald. Could someone respond to that please!

Hi, I get the ‚Error: Could not connect to MySQL server‘ MAMP start page error. Solved editing /Applications/MAMP/bin/mamp/index.php, around line #18:

$link = @mysql_connect(‚:/Applications/MAMP/tmp/mysql/mysql.sock‘, ‚root‘, ‚root‘);

put here your correct user/passwd and go!

Many thanks, was wanting to find a fix for this and just did a search and first result that came back. Best fix is to change the startup and shutdown scripts as noted.

Thankyou!

Thx for this
now it’s work!

That was very helpful – thank you!

what about using locomotive? how should we connect?

Gerade beim herumstoebern im Netz bin ich auf einmal auf deinem Blog gelandert. Und jetzt komme ich nicht mehr wirklich weg weil mir die Artikel welche du geschrieben hast richtig zu sagen. Sind schoen interessant geschrieben so das man sie gerne lie�t.

I am using MAMP and it’s not finding PEAR DB, please help me fix so I can use PEAR DB locally. MUCH appreciated!

Had the same problem on my debian linux installation, i.e. „Can’t connect to local MySQL server through socket /tmp/mysql.sock'“.

Fixed the problem by editing the wp-config.php file and changing the line:

define(‚DB_HOST‘, ‚localhost‘); // 99% chance you won’t need to change this value

to

define(‚DB_HOST‘, ‚localhost:/tmp/mysql.sock‘); // 99% chance you won’t need to change this value

Thanks toniyelca. your comment really helped me.

Thank you! You helped me out, too!!

thanks a mill

Simple solution is try this command:
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

[…] They sent me back the following link. http://www.fischerlaender.net/web-20/mac-os-x-trouble-with-mamp-mysql […]

Thanks. This article worked for my socket problem, but I now have a different problem. When I open mysql from the terminal, I have no database. Under MAMP, I can see all of my databases. Is there two different mysql installations? How can I link to the correct one? Thanks in advance.

And thanks again !

I just resolved editing, the my.cnf and comment next lines with ‚#‘:
#socket = /tmp/mysql.sock

thx too !!!

My problem is similar:

Dreamweaver (CS5) can connect and use the testing server. But when I try to create a connection Dreamweaver can’t see any databases and returns an unknown error.

In Dreamweaver’s databases window the 1st 3 boxes are ticked. I am trying to get a tick in the 4th box.

I’m using a MAC and MAMP.

At first I thought it might be due to another (different) version of MYSQL installed on my machine. I found a way to uninstall this but the problem still persists.

Thanks alot really helped! 😉

Thank you! Works as a charm 🙂

There’s also WebStart.

http://www.eosgarden.com/en/products/

Still not getting this. I’ve tried each of the suggestions, and get green lights for Apache and Mysql, but the same „Cannot connect to MYSQL server“ when I try and launch the start page. Reinstall allows MAMP to work again, but on restart encounter the same problem. Editing the startup and stop files isn’t even working.

Any further suggestions?

@jcbarb:

First check if mysql server is running in Activity Monitor.

open -a ‚Activity Monitor‘

Then check your PATH variable:

echo $PATH

Then try using „127.0.0.1“ instead of „localhost“ as host of your MySQL database server.

See:

MacPorts, MySQL, PHP5 and that socket thing ..

http://workbench.haefelinger.it/archives/162

Finally, you may have to open the firewall as described here:

http://docs.moodle.org/20/en/Complete_Install_Packages_for_Mac_OS_X

And last but not least have a look at the following video tutorial:

Installing MAMP on Mac OSX – with Debugging Tips

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

Good luck!

Thanks! Worked like a charm 🙂
That error had been frustrating me for some time.

Thanks a lot for the very useful link. It ended half an hour of frustration very easily.

You, sir, are a bloody genius.

Hi Stefan,
Thanks a lot for your article. I followed your tips and could run mysql by running „/Applications/MAMP/Library/bin/mysql -u root -p“.
However, on MAMP’s welcome page, when I click on the phpMyAdmin link, I got this error message: „#2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured) „.
Hove over the „phpMyAdmin“ link above, I see it’s a link to „localhost:8888/MAMP/phpmyadmin.php?…“. The phpmyadmin.php file in my computer is at „/Applications/MAMP/bin/mamp“ with the following content:

Do you have any idea how to fix the problem?
Thanks,

Never mind, Stefan. The problem went away after I restarted my computer (which is odd anyway). Thanks again for the article.

I had the same problem just now when trying to get ODBC Admnistrator to talk to XAMPP. I thought it might be useful for anyone googling the problem to point out that if you’re using XAMPP the command for creating a symbolic link is now:

sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock /tmp/mysql.sock

I edit the code and then refresh the page then the page refreshes but keeps the old code and doesn’t put the new code on.

FOR ANYONE WHO GETS A ‚FILE ALREADY EXISTS‘ ERROR:

The symlink he provided here is backwards. Run sudo ln -s /tmp/mysql.sock /Applications/MAMP/tmp/mysql/mysql.sock instead and that will fix your issue

I am on the last step of installing wordpress locally (see http://codex.wordpress.org/Installing_WordPress_Locally_on_Your_Mac_With_MAMP) and it’s telling me to „Visit your local site (localhost:port or localhost:port/wordpress), and enter the following information into the database setup form:“……. i am VERY new at this and i’ve tried both localhost:port & localhost:port/wordpress in my browser and neither of them work. HELP! …i’m so close, but so far…

Schreibe einen Kommentar
benötigt
benötigt (wird nicht angezeigt)
optional

Suchen