When installing on Mac OS X, using its pre-installed version of PHP but a later, downloaded install of MySQL (eg., 5.1, etc.), in the last part of the Drupal install, you may get a, "Error establishing a database connection."

First make sure the database name, username and password are all correct as you set them up.

The problem then may be in how Mac OS X connects to the database host on a local machine. Normally, in Drupal UI install, when testing on your own machine, this defaults in the "Host" field as, 'localhost.'

The quick and dirty work around, especially if this is just set-up for testing, is to change the case of of 'localhost' to 'Localhost.' Then it should work.

The more complete fix is type the following into a shell:

$cp /etc/php.ini.default /etc/php.ini
$sudo chmod +w /etc/php.ini

Then in "php.ini" in an editor, change the line reading as:

mysql.default_socket

... to:

mysql.default_socket = /tmp/mysql.sock

Then restart the Apache server on the Mac and it should be fixed.

This happens also on Wordpress, and a friend forwarded me this fix when I ran into the same problem installing Drupal on Mac OS X 10.5.6 Leopard with MySQL 5.1, from this WordPress fix detailed on this site about Mac Wordpress Error establishing a database connections.

Comments

zicount’s picture

I just wasted the last day trying to figure out why my local installation of drupal wasn't working.

I found this page - yay! - and the answer to try "Localhost" instead of the industry-standard "localhost" worked. Which is great.

But, what's *NOT* great is that this is a bug. This is *still* a bug. The original post is from 2009!

If this is a well-known issue, then please put it in the README file or even in the installation. ("If you are installing this on a Mac, please try "Localhost" under Advanced.") Or, hell, make the change yourself!

Grrrrr.

P.S. I've installed WordPress several times on several Macs since 2009 and *never* has this been an issue. So, either it's not a global issue (i.e., it's drupal's fault) or they've figured out how to address the issue. I hope Drupal does, too.