Support » Installing WordPress » The Infamous ‘Error establishing a database connection’

  • Resolved DeadTreeMe


    I’m trying to install WordPress on one of our local server and I’m getting the ‘Error establishing a database connection’ screen. I can sign on to MySQL on the command line with the same credentials, so I know that MySQL is running and the user and password are OK.

    Is there any way to get a more verbose error message to help me track down the problem?

Viewing 15 replies - 1 through 15 (of 26 total)
  • The 3 questions are pretty “verbose” – it tells you exactly what the problem is. If the user and pw is correct than your server name might be wrong.

    This seems to be a problem with Mysql 5.* installs. I was pretty taken aback with this error message as well…

    I found the solution elsewhere… (see below) Seems to be a password formatting incompatibility:

    Issue the command from your ‘MySQL>’ prompt:

    SET PASSWORD FOR some_user@some_host = OLD_PASSWORD(‘your_old password_here’);

    That solved it for me…! πŸ™‚

    See more at:

    Thank you NICK !

    Except that I don’t think the problem is covered by the three questions. Let me describe what I did and maybe that will make things clearer.

    I used the following command line to check on the MySQL user:

    mysql –user=NSBlogger –host=localhost –password=xx NSBlogs

    That worked with no errors. So I cut and pasted the information into the wp-config.php file but WordPress wasn’t able to make a connection.

    Check it for typos, spaces, wrong quotes…
    e.g. 'localhost' – is OK
    ' localhost' – is not OK

    Again, I did the same things, and couldn’t figure out what the problem was. All strings were correct, etc, etc…

    The OLD_PASSWORD trick solved it. It’s probably something to do with character representation for passwords from within MySQL 5.*

    Try it, and if it doesn’t work, you’d only be back where you started…. πŸ˜‰

    PS: Not sure what the ‘three questions’ are.

    Nope, the quotes match, no extraneous spaces.

    Is there some sort of debugging mode that would show exactly where the code is choking?

    Two posts above by theburningdesire were caught by Akismet (falsely) as spam.
    I just released them…

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Explanation of the OLD_PASSWORD problem:

    Versions of MySQL after 4.1.1 use a new password hashing algorithm.

    If your version of PHP was compiled with a version of MySQL earlier than that, then it is not compatible with the new password hashing algorithm. You can check this by looking at the phpinfo() page and seeing what version of the MySQL Client API is being used. Versions after 4.1.1 should work without problems, earlier versions will not work at all on MySQL 4.1.1 and later servers without the OLD_PASSWORD trick given above.

    Possible solutions:

    1. The OLD_PASSWORD given above will force that user to use the old password hashing method. This is less secure, and should be avoided if possible.

    2. Many hosts use PHP 4 by default, but offer a way for you to use PHP 5. This PHP 5 version may have different versions of the MySQL client libraries compiled with it. Ask your host how to switch you to PHP 5. This is the recommended solution anyway, as PHP 4 support is going away eventually. Even the PHP developers will not be supporting PHP 4 any longer after sometime this year.

    Darnit, I can’t get the old_password trick to work. I’m clueless what to do next. πŸ™

    I’ve passed the OLD_PASSWORD tip along to our database admin.

    I’m a little confused by Otto42’s note. We are using PHP5 and MySQL is working with it. Could there be another problem?

    Anyway, I’ll update when we’ve tried the OLD_PASSWORD method.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    DeadTreeMe: You may not have the old_password problem then.

    When you look at the output of phpinfo(), what is the “Client API Version” in the MySQL section?

    BTW, if you get the “Error establishing a database connection”, then the username, password, or server is wrong in some way. Period. Nothing else can cause that. The old_password problem is basically the password being sent incorrectly by an older version of the MySQL client in PHP.

    You can test this sort of thing by making a new PHP file with the following and running it:

    $db = @mysql_connect('server', 'username', 'password');
    if (!$db) echo "connection failed";
    else echo "connection succeeded";

    If this code returns connection succeeded, then WordPress will work with the same server, username, and password.

    Actually our problem was much simpler, sort of. πŸ™‚

    For whatever reason, MySQL won’t recognize localhost but does the IP of the server. Hey, I didn’t set up it. πŸ™‚

    Thanks to everyone for all your help!

    Thanks Otto42 for the detailed explanation. I had a feeling it was something along those lines and decided to not dig any deeper once it worked for me (bad, I know…).

    I’ll make sure to update my MySQL client due to the security concern, as well as future deprecation issues.

    In any case, it’s worth having this info in the forum, as the error can be very deceiving and turn it into a major ‘head scratcher’ like it did to me: “I’m sure I typed the info correctly many times…!”…

    Thanks again for the great help!

    This is all very interesting, but I’m just trying to connect via Yahoo–they’re supposed to be managing all of this server business–and I’m getting the same exact error message as these folks with access to the server running the show.

    Why would I be getting this error? And I was connected and working fine, setting up the site–when hey presto, I get this error message.

    I had this error message and tried all of the above. In the end I changed

    define('DB_HOST', 'localhost');

    to my database host name and all worked fine.

    define('DB_HOST', '');

    Hope this helps someone.

Viewing 15 replies - 1 through 15 (of 26 total)
  • The topic ‘The Infamous ‘Error establishing a database connection’’ is closed to new replies.