Troubleshooting: Database not connecting with custom MySQL and pre-installed PHP for Mac OS X

Last modified: February 26, 2009 - 22:23

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.

 
 

Drupal is a registered trademark of Dries Buytaert.