Wordpress “error establishing a database connection” on OS X Leopard

Posted on December 13th, 2007 by Jeff

If you are getting this error on your local WordPress installation using Mac OS X Leopard, there is a simple fix. You might be seeing this error even though PHP is working fine, and MySQL is working fine. In order to get WordPress to work create a php.ini file.


sudo cp /private/etc/php.ini.default /private/etc/php.ini

Change permissions and edit the file


sudo chmod 777 /private/etc/php.ini
vi /private/etc/php.ini

Change mysql.default_socket = [blank] to


mysql.default_socket = /private/tmp/mysql.sock

Restart Apache and you should be good to go!


sudo apachectl restart

13 Comments so far

1 | Alf Mikula

Thanks, that worked like a charm!

Posted at 7:18 pm on December 18th, 2007
2 | Dibi Store

Hey thanks you!

Posted at 1:52 pm on January 9th, 2008
3 | kw

Cool… can you edit php.ini with pico? It makes more sense to me. :-)

I’m on 10.4 but am going to give it a try… thanks for the tip!

Posted at 1:28 pm on March 3rd, 2008
5 | Wordpress Themes

How effective has wordpress been on Mac? I have not heard alot about its use on Mac.

Posted at 2:33 pm on March 25th, 2008
6 | Jeff

@Wordpress Themes, It doesn’t matter if you’re running a Mac or a PC or anything else for that matter, as long as you have the correct versions of PHP and MySQL. See http://wordpress.org/about/requirements/ for more info.

Posted at 9:23 am on March 26th, 2008
7 | :(

What does that mean? Lol.

Posted at 10:14 am on April 3rd, 2008
8 | L. S.

Yes, that works, but don’t chmod 777; you end up giving anyone the right to edit that file and possibly hack parts of your system. Just set the “mysql socket” line mentioned.

Posted at 10:44 am on May 2nd, 2008
9 | L. S.

Yes, that works, but don’t chmod 777; you end up giving anyone the right to edit that file and possibly hack parts of your system. Just set the “mysql socket” line mentioned. There shouldn’t even be a “7″ anywhere in those permissions.

Posted at 10:47 am on May 2nd, 2008
10 | bimble

Brilliant, worked perfectly. and even better, you were the first hit in google :)

Posted at 1:54 am on May 16th, 2008
11 | Wordpress on OS X Tiger - “error establishing a database connection”

[...] info on locating and modifying your php.ini file, see the Bust Out Solutions [...]

Posted at 12:57 pm on May 31st, 2008
12 | Leslie Wong

Thanks for this tip. It worked for me in Tiger, 10.4.11 on a PowerBook G4 12″.

Posted at 2:21 pm on October 20th, 2008
13 | Chris

Absolutely amazing, this one frustrated me for a long time. One thing to note is that I have found multiple possible causes for this. For future people coming here, to diagnose whether this is the issue causing the problem it is useful to add:

echo(mysql_error());

to the wp-db.php file within the wp-includes directory just before the html for the error is printed. If it mentions socks in the output error message on refresh, you can know this is the problem. cheers!

Posted at 1:51 am on April 1st, 2009

Write a new comment


Comment: