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
17 Comments
Alf Mikula
—
Thanks, that worked like a charm!
Dibi Store
—
Hey thanks you!
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!
The Paradiso » Wordpress “error establishing a database connection” on OS X Leopard
—
[...] From : http://bustoutsolutions.com/blog/2007/12/13/wordpress-error-establishing-a-database-connection-on-os... [...]
Wordpress Themes
—
How effective has wordpress been on Mac? I have not heard alot about its use on Mac.
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.
:(
—
What does that mean? Lol.
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.
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.
bimble
—
Brilliant, worked perfectly. and even better, you were the first hit in google
Wordpress on OS X Tiger - “error establishing a database connection”
—
[...] info on locating and modifying your php.ini file, see the Bust Out Solutions [...]
Leslie Wong
—
Thanks for this tip. It worked for me in Tiger, 10.4.11 on a PowerBook G4 12″.
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!
Michael Grech
—
Good work, this works on Snow Leopard as well.
thiudis
—
Thanks – worked great!
Spenser
—
Thanks for this. @Chris, good advice for future errors.
Dave White
—
Thanks for the fix. What was strange for me was that everything was working fine one day and the next I was getting this error. I did run a security update from Apple in between though.