8

When I try to access my WordPress site as localhost, I get:

Error establishing a database connection`.

How can I debug this problem? Where are logs I can see?

I am able to login to MySQL with user wordpressuser on localhost. I seem to have correct grants for wordpressuser on database wordpress:

root@myhost# mysql -hlocalhost -uwordpressuser -pmypassword 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 109
Server version: 5.5.37-0+wheezy1 (Debian)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show grants for wordpressuser@localhost;
+----------------------------------------------------------------------------------------------------------------------+
| Grants for wordpressuser@localhost                                                                                   |
+----------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wordpressuser'@'localhost' IDENTIFIED BY PASSWORD '*somepassword' |
| GRANT ALL PRIVILEGES ON `wordpress`.* TO 'wordpressuser'@'localhost'                                                 |
+----------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

But when I run mysqlaccess, I get:

root@myhost# mysqlaccess localhost wordpressuser wordpress -pmypassword
mysqlaccess Version 2.06, 20 Dec 2000
By RUG-AIV, by Yves Carlier ([email protected])
Changes by Steve Harvey ([email protected])
This software comes with ABSOLUTELY NO WARRANTY.
Password for MySQL user wordpressuser: 

Sorry,
An error occured when trying to connect to the database
with the grant-tables:
* Maybe YOU do not have READ-access to this database?
* If you used the -U option, you may have supplied an invalid username?
  for the superuser?
* If you used the -U option, it may be possible you have to supply
  a superuser-password to, with the -P option?
* If you used the -P option, you may have supplied an invalid password?

wget localhost fails with connection refused:

user@myhost:~$ wget localhost
--2014-06-08 01:11:29--  http://localhost/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:80... failed: Connection refused.
Connecting to localhost (localhost)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 500 Internal Server Error
2014-06-08 01:11:29 ERROR 500: Internal Server Error.

My wp-config does seem to have the proper credentials (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST).

How can I debug this problem?

1
  • 1
    The [wordpress] tag is fine to have around since the OP is clearly encountering their problem within a WordPress installation. This may not be a WordPress-specific issue, but for all we know it could well have been caused by WordPress itself. Commented Jun 8, 2014 at 10:44

1 Answer 1

0

I managed to temporarily work around the issue as follows:

Trying to find the place where php accesses the mysql database, I did a a

grep Ri db.user /var/www

to find that

/var/www/wp-includes/load.php

creates the database in this line:

$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );

I tried hard-coding the values for DB_USER. DB_PASSWORD, DB_NAME, DB_HOST, and the site does load on the localhost now. Clearly, there was a mismatch between the values defined in wp-config.php, and those that actually get passed to new wpdb(...), though I haven't been able to track that down further yet.

Unlike what was suggested in one of the comments:

  1. This was not a problem with the web-server. The site works normally now, from within localhost or from outside.

  2. The command wget localhost does work correctly now. It downloads an index.html which contains the wordpress setup page

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.