If you are getting this error on your local WordPress installation using Mac OS X Lion, 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


8 Comments
Wordpress Error Establishing a Database Connection After Upgrading … : FRIENDDAT BLOG
—
[...] the article here: WordPress Error Establishing a Database Connection After Upgrading … Category: TipsTags: chmod-777 > [...]
Lenart
—
Depends on the type of connection used you might need want to change one of the following:
mysql.default_socket
pdo_mysql.default_socket
mysqli.default_socket
Check to see if /private/tmp/mysql.sock exists. Some people also have symlink to /tmp/mysql.sock.
Good luck!
Shyam
—
I ran into the same issue. Looks like the OSX Lion upgrade makes a backup of your previous php.ini file and the previous php.ini.default file. These backups are under /etc, right next to the new php.ini.default file.
On my machine, the mysql.default_socket is at /tmp/mysql.sock, so you want to make sure that your PHP ini points to the correct locations.
Gerald
—
Didn’t work at all for me. Still get same error.
Conexão com Mysql no Mac OS X Lion | Oliver Heilmair
—
[...] Tentei de todas as formas conseguir contornar o problema, mas tive que fazer uma rápida pesquisa no Google para encontrar uma explicação do problema (Fonte). [...]
sss
—
thanks! this worked don’t know why lion changed the location of the mysql socket in the php.ini.
Jon
—
Worked perfectly. Thanks very much.
WordPress development on Mac OS Lion | rossiep.com
—
[...] Ran into a snafu straight away, resolved by this post: http://bustoutsolutions.com/blog/2011/07/29/wordpress-error-establishing-a-database-connection-after… [...]