Mac OS X Tiger database connection problems (and solution)
I’ve experienced some horribly frustrating problems the last week or so with installation since deciding I wanted to move to WordPress.
I’m running Mac OS X 10.4.4 and have been wanting to try out WordPress locally (localhost) first. I downloaded and installed MySQL then WordPress, but WordPress steadfastly refused to connect to a database I’d set up for it, always returning: “Error establishing a database connection. This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.”
I’ve just spent quite some time in the #Wordpress IRC channel, where ringmaster ran me through the process of tapping setup-config.php to create a new wp-config.php, just in casse my settings were off. No luck; same error.
PotterSys gave me some php code to check that my PHP was talking to my MySQL properly. That code, which just tested a database connection, returned:
Warning: mysql_connect(): Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (2) in /path/to/test/script.php on line 2
Uhm, MySQL is not working
ringmaster said this showed that there was something wrong on my system in PHP talking to MySQL and, if not solved, just about nothing requiring MySQL would work.
So I googled that error in a Mac OS X context. Turns out Mac Drupal users were experiencing the same unfathomable problem at the Drupal messageboard – it’s all about the MySQL socket. One user said…
The version of PHP that Apple included with Mac OS X 10.4.4 has mysql.default_socket set to “/var/mysql/mysql.sock”, before it was “/tmp/mysql.sock”. They change it for some security reasons I believe.
The binary version of MySQL from mysql.com use “/tmp/mysql.sock” so one has to change.
I choose to make PHP look for “/tmp/mysql.sock” by setting this in /etc/php.ini.
The necessary variable setting used by the guy is included in that post.
So I sought out my php.ini. Alas, I only had a php.ini.default. No problem. A person in the #php chatroom said you can just edit the setting and rename the file to take away the .default extension.
After doing so, the error is missing from the test script, setup-config.php works, the rest of WordPress looks like it now wants to works and I hope to be a happier person (except when I look at .htaccess and directory name formats).
Anyway, I really wanted to throw this out to the community because it was a hell of a job getting it fixed, it’s totally not something you would think of, especially if, like me, you just wanted to download WordPress and go. Apparently, it’s all because Apple changed the location of the MySQL socket in OS X 10.4.4.
So, thanks to those who helped me and I hope you can benefit from this.
- The topic ‘Mac OS X Tiger database connection problems (and solution)’ is closed to new replies.