[resolved] The Infamous 'Error establishing a database connection' (27 posts)

  1. DeadTreeMe
    Posted 8 years ago #

    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?

  2. moshu
    Posted 8 years ago #

    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.

  3. theburningdesire
    Posted 8 years ago #

    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: http://www.railshostinginfo.com/blog/2007/03/19/wordpress-installation-error-establishing-a-database-connection/

    Thank you NICK !

  4. DeadTreeMe
    Posted 8 years ago #

    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.

  5. moshu
    Posted 8 years ago #

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

  6. theburningdesire
    Posted 8 years ago #

    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.

  7. DeadTreeMe
    Posted 8 years ago #

    Nope, the quotes match, no extraneous spaces.

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

  8. moshu
    Posted 8 years ago #

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

  9. 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.

  10. andriaandco
    Posted 8 years ago #

    Darnit, I can't get the old_password trick to work. I'm clueless what to do next. :(

  11. DeadTreeMe
    Posted 8 years ago #

    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.

  12. 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.

  13. DeadTreeMe
    Posted 8 years ago #

    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!

  14. theburningdesire
    Posted 8 years ago #

    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!

  15. audioaudio
    Posted 8 years ago #

    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.

  16. BeddgelertWoodcraft
    Posted 8 years ago #

    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', 'database.yourhost.co.uk');

    Hope this helps someone.

  17. asaintprix
    Posted 7 years ago #

    I had the same problem as above, so I tried the old password bit and that didn't work.

    I was migrating my wordpress install from another computer so I knew everything should work properly, but for some reason it refused to work. I upgrade from a 4.1.x version of MySQL to 5.0.67.

    I reviewed settings in the wp_config.php file and decided to change the DB_HOST value from 'localhost' to '' and voila! It worked immediately.

    I don't know if it's bad from to use the ip address, but it seemed to work.
    I have no clue why it didn't work with localhost list as db host. Maybe someone smarter can post why this is the case. Anyway, glad it's working now. Hopefully this helps someone else.

  18. thinkpixels
    Posted 7 years ago #

    After pulling some hair out for an hour I thought I would pass on a solution I found.

    I tried pretty much everything up here, but nothing worked.

    For those using cPanel, this might be something good to know.

    I tried to name my database using underscores like 'my_wordpress' well Cpanel took the name fine but showed it as 'user_mywordpress' which is fine so I plugged that in thinking it stripped the _ (underscores) from the string. Turns out it didn't. As soon as I deleted that database and created a new one called 'mywordpress' and created a new user and password (for good measure) and assigned it to the new database, it worked. I am running MySQL 5.0.51a

    Hope it helps someone. I actually was inspired to check the database name when i visited this link:

  19. hilmon
    Posted 7 years ago #

    Yeah, I was 1 of the 1% and needed to enter the IP as 'localhost' didn't work!!... maybe that "local host should work for 99%" should be changed to 98.9% :-) ... great forum by the way .. problem solved in less than 5 minutes!!

  20. azul007
    Posted 7 years ago #

    i wrote every line right.
    but it just doesnt work at all

  21. nicefella
    Posted 7 years ago #

    try adding the default port number that you set in php.ini next to the host address field like or :3307.

    this worked fine for me.

  22. homerzhu
    Posted 7 years ago #

    very good, i also have this problem

  23. beardie
    Posted 7 years ago #

    Hey all

    I have been encountering the same error message and have tried all of the above to no avail.. I am trying to move the site from an existing install to a host using cPanel and PHPmyadmin. The server is running:
    PHP version 5.2.6
    MySQL version 4.1.22-standard-log

    I have tried doing a fresh install also to no avail, just getting the error when attempting to go to the install.php page. So its clearly having some toubles with the usr / pwd as mentioned above...

    There are other sites running on this server but not WordPress, so im trying to install into a sub directory. When creating the database and usr it auto adds a prefix, example: I enter database name 'database01' it creates 'owner_database01' the same with the username...
    Is this normal? I have tried using both variations in the wp-config.php file and neither work...

    Any helpp would be very useful.

  24. Camgee
    Posted 7 years ago #

    Hello, I am getting this same message and I see the problem. My password doesn't match in wp-config.php. How do I change it? Or do I make the database password match what is in wp-config.php?

  25. kirakar
    Posted 7 years ago #

    I have got the Error establishing a database connection message since Saturday. Didn´t touch any files. My blog was working since I upgraded to 2.7 a few days after the release so this error comes as a surprise. I have done many posts since then. I checked my config file and is okay. I haven´t received any messages from my hosting provider... I am lost with this problem and need some help. I don´t know how to use prompt command neither have cpanel... So if somebody can give me some help like for dummies I will appreciate it... Please!

  26. Eglinton
    Posted 7 years ago #

    I am having the same problem as the member above. My site has been working fine until last night when I got the message Error establishing a database connection. I have no idea why this happened. I need help, please.

  27. ngelkins
    Posted 7 years ago #

    I realize this is an old thread but I'm having trouble with this same issue and maybe someone can help. Have followed all the suggestions here with no luck. I tried creating both a mySQL4 and a mySQL5 user and I still have the same problem. Have checked and rechecked (and rechecked) the relevant lines in the wp-config file. Still no luck.

    Question: I'm confused about how to use the OLD_PASSWORD trick mentioned above since I don't have the ability to go to my web host and find an MySQL> prompt. It doesn't work that way. I can create a mySQL user and a database, but there's no opportunity to do anything with it through the webhost. How do you do that?

    Sorry for being so thick, but I've just spent hours going through the forums and I must be misunderstanding something. Where does the SET PASSWORD FOR some_user@some_host = OLD_PASSWORD('your_old password_here'); text go??

Topic Closed

This topic has been closed to new replies.

About this Topic