views:

65

answers:

5

This is driving me nuts! I have a test instance of Wordpress installed on my MacBook Pro, which has suddenly stopped working. If I head for http://localhost:9003/wp-admin/ I get:

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.

Are you sure you have the correct username and password?

Are you sure that you have typed the correct hostname?

Are you sure that the database server is running?

If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

Hmmph! I haven't touched the config for ages. Here's how the relevant lines look right now:

define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', 'wordpress');
define('DB_HOST', 'localhost');
$table_prefix  = 'wp_';

The values are all good:

$ mysql -h localhost -u wordpress --password=wordpress \
> wordpress -e 'select user_login from wp_users'
+------------+
| user_login |
+------------+
| simon      |
+------------+

There's nothing in the MySQL error log, nor in Apache's error log. I've tried using a different MySQL user and a different database, but I get the same error. I'm scuppered - any WordPress gurus out there know what I'm missing?


Output of php --ri mysql:

$ php --ri mysql

mysql

MySQL Support => enabled
Active Persistent Links => 0
Active Links => 0
Client API version => mysqlnd 5.0.7-dev - 091210 - $Revision: 294543 $

Directive => Local Value => Master Value
mysql.allow_persistent => On => On
mysql.max_persistent => Unlimited => Unlimited
mysql.max_links => Unlimited => Unlimited
mysql.default_host => no value => no value
mysql.default_user => no value => no value
mysql.default_password => no value => no value
mysql.default_port => no value => no value
mysql.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock
mysql.connect_timeout => 60 => 60
mysql.trace_mode => Off => Off
mysql.allow_local_infile => On => On
A: 

Sure web sharing is turned on?

And MySQL is running via the Preferance Pane: http://dev.mysql.com/doc/mysql-macosx-excerpt/5.1/en/mysql-installation-macosx-prefpane.html

Might try phpmyadmin to check the database: http://www.phpmyadmin.net

songdogtech
Yes to apache and mysql running. (Web sharing is clearly turned on, or I wouldn't get the Wordpress error page. Ditto mysql or I wouldn't get the command-line client output.)
Simon Whitaker
A: 

Something to do with the allowed client host part of the user account?

http://dev.mysql.com/doc/refman/5.1/en/adding-users.html

tomfanning
+1  A: 

What is the output of php --ri mysql on the command line?

Gipetto
Looks healthy enough - have added to question
Simon Whitaker
And the socket file is in fact at `/var/mysql/mysql.sock`?
Gipetto
Also, I assume you've set WP_DEBUG to true and seen if that gives any more detailed info on screen or in the apache/php logs?
Gipetto
No, the socket file was in /tmp/mysql.sock! It looks as though a security update to Mac OS X 10.6.4 a week ago (http://support.apple.com/kb/HT4312) was implicated here. PHP was upgraded - only a minor point release (5.3.1 to 5.3.2) but I suspect it may have been compiled with a different default mysql.sock location. Adding an /etc/php.ini and specifying the correct mysql.sock location seems to have done the trick. Thanks Gipetto!
Simon Whitaker
weird... my boss just hit this exact same thing. Glad it worked.
Gipetto
A: 

If you truly didn't change any of your configuration settings, then maybe the database connection can't be established for mundane reasons. Perhaps a silly question, but did you try restarting your computer or at least MySQL? Maybe MySQL is just running low on resources and cannot service your web site's request.

Jacob
Good suggestion, but didn't help I'm afraid. I did restart MySQL (and eventually, out of frustration, my laptop!) but no dice. Thanks for the idea though.
Simon Whitaker
A: 

This is exactly the problem, and the solution.

http://appletoolbox.com/2010/08/phpmysql-broken-after-security-update-2010-05-fix/

Simon Whitaker