N00b MySQL/WP config question

September 17, 2012 6k views
Hi guys, It's been years since I worked in web hosting - I'm sure the answer is super easy, but it's late and my brain won't grok anymore tonight: Ok, so (obvious strings have been changed to protect, well, me): CREATE DATABASE my_wp_db; CREATE USER my_wp_db_un@localhost; SET PASSWORD FOR my_wp_db_un@localhost= PASSWORD("mycleverwppw"); GRANT ALL PRIVILEGES ON wordpress.* TO my_wp_db_un@localhost IDENTIFIED BY 'password'; (or is it) GRANT ALL PRIVILEGES ON wordpress.* TO my_wp_db_un@localhost IDENTIFIED BY 'mycleverwppw'; (I've tried it both ways) FLUSH PRIVILEGES; EXIT sudo nano ~/wordpress/wp-config.php // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'my_wp_db'); /** MySQL database username */ define('DB_USER', 'my_wp_db_un'); /** MySQL database password */ define('DB_PASSWORD', 'mycleverwppw'); /** MySQL hostname */ define('DB_HOST', 'localhost'); Can’t select database We were able to connect to the database server (which means your username and password is okay) but not able to select the my_wp_db database. Are you sure it exists? Does the user my_wp_db_un have permission to use the my_wp_db database? On some systems the name of your database is prefixed with your username, so it would be like username_my_wp_db. Could that be the problem? Do you guys see any notable syntax errors? Are there logs I could look at to help me? Any advice is welcome - thank you!
3 Answers
To test whether or not the connection to the database works and has the correct privileges you can do:

# mysql -u username -p
mysql> use databasename;
mysql> create table my_test;
mysql> drop table my_test;

If you get an error running the mysql command that means your username and password aren't right.

If you get an error on the use statement that means the user that you accessed mysql with doesn't have any privileges on the database.

If you get an error on the create and the drop that means your user doesn't have create privileges which means wordpress will not install.

A simple syntax for creating a user, granting privileges, and setting a password in one command is:
mysql> GRANT ALL ON databasename.* to username@localhost identified by 'password';

Based on your error it seems that the user/pass allows you to connect but that the user doesn't have privileges.

So running that GRANT command should fix things for you.
Wheee! Tried it a couple of times using my existing un - no dice. Went ahead and made a brand new un/pw according to the GRANT command you posted - refreshed the wpconfig file and voila! Thank you so much!
Awesome, glad to hear it!
Have another answer? Share your knowledge.