Skip to main content

“Error establishing a database connection” With XAMP, MySQL and WordPress

Thought some people might find it useful to see how I managed to solve this…

So, this week I determined to do a little more work on the code for this blog – a new plugin.  However, as I have recently updated my laptop I needed to re-install all the tools – Eclipse, Ant, XAMPP – and setup the XAMPP test instances of the blog.

I ran up XAMPP and used phpMyAdmin to setup a test WordPress database and user.  Then I used Eclipse to edit the wp-config.php file for the XAMPP installation and finally a little ANT script to rebuild the blog into the XAMPP directory.

At this point, I expected to launch immediately in to the blog at “http://localhost:8080/” ready to do the setup and install a backup from the live blog to play around with.

No such luck!  Instead I got the following:

Screenshot - Error establishing a database connection

Well, I tried all the obvious things – checked the password, username, checked everything was up and running.  Nothing obvious.  I added and removed the user and database several times – but to no avail.

I tried Google – and found a few others with suggestions, but nothing that worked.

But, eventually, I noticed that the one detail was a little odd.  When creating the users I had left the “Host” setting to be the default “Any host” – which results in the “Host” column in the Users list showing “%”.

So, I changed the user (using the Edit Privileges link) and set the Host to be “localhost” – using the “Create a new user with the same privileges and … delete the old one from the user tables.” option.

That worked.

I’ve shown the user that worked (wordpress_user) and another one that causes the problem (badwp_user) in the screenshot below:

Screenshot - phpMyAdmin showing a "good" and "bad" user.

Hope that helps some of you.

Tags: , ,
Posted in WordPress

20 comments on ““Error establishing a database connection” With XAMP, MySQL and WordPress”

  1. RS says:

    Just wanted to thank you as I was having this problem and it was driving me crazy. Nothing I could find helped aside from this which seems to have been posted just 5 days ago. Just in time!

  2. peshu says:

    create a database manually in phpadmin. point that database name in your wp-config.php script and run the script.

  3. Ben says:

    Thank you…

  4. raghavendar says:

    The problem may be due to high memory usage and you may not have created the swap file. Follow the link to get the procedure to create swap file

  5. dr0g0 says:

    Thank you, looked at various fixes but your artitcle helped as I had not set the user to localhost.


  6. Ugochukwu says:

    Thanks very much, you do not just helped me out, youvteqch me something new.thanks ones again.

  7. Snyders says:

    Thank you, only page that show this real solution. You rock, man!

  8. Sjoek says:

    Hi Simon, Thank you so much for this! Googled allot but this is the only good answer i could find on the whole www.

  9. alexandra says:

    THANK YOU! It has eaten all my neurons so thank you for postin this.

  10. shailender says:

    thank u so much buddy.. wasted my precious 2 hour thanks..

  11. sam says:

    Thank you so much.

    All along, I had assumed that Any host meant any host including localhost.

    I have been struggling with this for days until your post saved me.

    Thank you

  12. Brad says:

    Thanks alot. It really solved the issue.

  13. J says:

    Thank you. With the help of this article the 5-minute ‘easy install’ actually took 3 minutes, plus the 2 hours it took me to find this article.

  14. Jayesh says:

    Thank you .. that worked for me too.

  15. aida says:

    thanks! that did the trick.

  16. Hernan says:

    Thanks man, this was driving me crazy.

  17. JG says:

    Thank you sooo much! You are my master :))))

  18. Theo says:

    Thanks buddy ! It worked for me, I lost so much time trying to figure it out

Leave a Reply

Your email address will not be published. Required fields are marked *