Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Error establishing a database connection

Hey everyone. I am trying to install wordpress locally on my pc (windows 7) with xampp. I have followed the directions to the T and still can not get passed this Error establishing a database connection. I have even gone as far as uninstalling xampp and starting over from the beginning twice. I have turned off my firewall and am really out of ideas on what to do. any help would be greatly appreciated!

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.

10 Answers

Matt Campbell
Matt Campbell
9,767 Points

The X next to the green highlighted word is to delete the module from XAMPP so has no bearing.

What details are you using in your wp_cofig.php file? Have you prefixed your database with anything other then wp_?

Use these settings, they're the default and should work.

Server - localhost, username - root, password - (leave it blank. no password for root user). prefix - wp_

Prefix is always wp_ unless you've changed it. It's the last box you see during install and has wp_ in there as standard.

Thank you. Leaving prefix as wp_ and password blank worked.

Did you try to delete a database and create a new one? Cz it stores that first information that you've set and it's using it again and again.

I will try that now.

no that didnt work. thank you though.

.

Sorry - Usually I delete all the stored database and reset my config.php - and do the process again -(creating a new database and setting up a new config.php file) that should work... and as you said the connection is error so check your passwords and usernames.

cdcol data information_schema mysql performance_schema phpmyadmin test webauth wp_portfolio (this is the one i am using for the course)

Can I delete all these databases that came with the install or should I leave the rest of them alone?

cdcol data
information_schema
mysql
performance_schema phpmyadmin
test
webauth wp_portfolio (this is the one i am using for the course)

Can I delete all these databases that came with the install or should I leave the rest of them alone?

I will delete it again. I am recreating a wp-config.php page now.

// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wp_portfolio');

/** MySQL database username */ define('DB_USER', 'root');

/** MySQL database password */ define('DB_PASSWORD', 'root');

/** MySQL hostname */ define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', '');

delete the one you created - wp_portfolio in phpMyAdmin

ok. still no dice. i deleted and created wp_myportfolio and still same thing with the new wp-config.php.

I have both the Apache and MySQL running on XAMPP Module shows green but the modules service have a red X. Does this matter?

Thank you very much, btw

I am mamp user (mac) - but it sounds like it does matter. Check your ports and path to your folder in your hosts tab (if there is one)... check that your indexes are checked... follow this link with the right installation : http://teamtreehouse.com/library/build-a-simple-php-application/getting-started-with-php/install-php-on-windows-7

I am uninstalling and reinstalling everything again. I will try leaving the password blank and leaving the prefix the same when I get it back up.

In the course they say to change it to wpWPP_ . Also in the course they say to use the password root...

I followed this course and it worked for me - so good luck

Holy cow ok its working now :) Thank you both!

Leaving prefix at wp_ and password blank worked. Those were the only two things i did different from the course.

Cheers