Error Establishing a Database Connection

Hi Everyone,

I am adding two new websites to my linode . It was installed using the prebuilt wordpress stack script so I was never sure what the user name for the mysql was. I am trying to import the database using mysql -u username -ppassword database_name < FILE.sql but I am getting permission problems. I have tried the command to list mysql database users but I also get an error about permission for that. What should I do here? is the site / database I am trying to link.

PS :: After doing this and getting to this part, my website that was previously up is now having a database issue!! I did not even touch anything regarding that website ! Can anyone shed some light on this I am at a loss of ideas.

19 Replies

Can you log into mysql using the -u mysqlrootuser -p option (no db name and no input file)?

If you can log in as root, check the permissions for the user and db that you're trying to use to import your sql file.

I ran a line in sql to figure out the users since I was not aware of them due to the fact I used a stack script.

The output came out with this

| user             |
| root             |
| root             |
|                  |
| root             |
|                  |
| debian-sys-maint |
| root             |
| wordpress        |

I got the line of code to transfer the sql file into mysql database to work but it does not seem to be connecting. Still having the error establishing a database connection.

When this line executed properly for is when the site ( that was already running became effected.

I guess the first question is how to get my original sites database linked back up. Then move to figuring out the other sites. Any thoughts on how I would accomplish this?



Am I correct in assuming that you're using the 'wordpress' user in your db configuration settings? What do you get when you run this command in mysql:

show grants for 'wordpress'@'%' ;


I would assume so yes, that was how the stack script was set up as far as I know.

I ran that line and came out with this,

ERROR 1141 (42000): There is no such grant defined for user 'wordpress' on host '%'

Which I would assume means there is no permissions set to any users? Appreciate your time and help MSJ !

EDIT :: I am not a fan of having multiple users since I am the only person using the server. Would if be possible to simple have one master user that can control all the databases?



I was guessing that your database user for your site was 'wordpress'. It's never a good idea to have your website or web application use the root user for database access. It's is a very bad security practice.

What user is defined in your wp-config.php file? It looks something like this:

/** MySQL database username */
define('DB_USER', 'your db user name');


Just went through all that, checked all settings for database 'wordpress' in my wp-congif.php and it looks like this

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

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

/** MySQL database password */
define('DB_PASSWORD', ‘passwordhere’);

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

Check all the settings on the SQL side and seems to be good. Any ideas from here?


You are using the 'wordpress' mysql user but have not given it any privileges (based on your previous posts). That is why it can't access the database.

You need to give the 'wordpress' mysql user the correct permissions to access the 'wordpress' database or use a different mysql user to connect to the database.

@Main Street James:

You are using the 'wordpress' mysql user but have not given it any privileges (based on your previous posts). That is why it can't access the database.

You need to give the 'wordpress' mysql user the correct permissions to access the 'wordpress' database or use a different mysql user to connect to the database.

How would one achieve this?


How would one achieve this? Running this command in mysql will do it: GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
"wordpress.*" refers to the database and "'wordpress'@'localhost'" refers to the user.

I have granted permission but still no luck. There were also 0 rows effected which makes me think that wasn't the problem? Thoughts? This is running me around in circles :P


You'll also have to "FLUSH PRIVILEGES;"

It still may say '0' rows affected. You should try to see if Wordpress connects.

Yes I have been using that command after doing changes in my SQL. Still no go. The site I'm trying to connect is if that helps anything.

Did you try importing the database? If you have't done the "mysql -u username -ppassword database_name < FILE.sql" yet then you can't connect because the DB doesn't exist.

I will try that out and let you know how it goes, I am just not too sure why I would need to do that after I simply added a few virtual host files. I never even messed with the databases regarding this website. Will edit post when I have more of an idea. Thanks MSJ .

EDIT :: I never made a SQL backup for my main website although all the actual web files are unaltered from the working config. Did not expect this site to go down and have DB issues while working on a completely different site :| . Is there by default a sql file in the contents of the web folders I can use to link?

EDIT EDIT :: Just found out there is a way to dump the database info into a sql file which I can maybe use to connect the site back up? Is this possible? I am having trouble using the command mysqldump -u [username] -p[password] [databasename] > [filename.sql] - it seems to go through without any output but I have no idea where that sql file would be if it was even created. Thanks again !


I am having the same problem, but I am using the wordpress walkthrough install so the error is:

"We were able to connect to the database server (which means your username and password is okay) but not able to select the [databasename] database."

If I manually put the info into a wp-config.php file, I get your "Error establishing a database connection" error.

I've double checked for typos, I've tried localhost,, linode_IP with no luck (also changing the host in mysql permissions).

I can access the database using the command line mysql -u my_user -h -p and use database my_database;.

Any suggestions?

My databases are both accessible and permissions are set as well but I can not seem to get a connection between the two. Would love it if someone could shed some more light upon this one.

EDIT :: Just checked and make sure the 'wordpress' DB has information in it and it seems to all be there, Just not sure how it got disconnected from my site in the first place. The answer must be so trivial.

EDIT EDIT :: Still plugging away at this for the 3rd day straight .. all of my sites are getting this SAME error. The answer has to be the same throughout all the sites, seems like theres a problem with sql talking to the wordpress config files. Been scouring the web but nothing it turning up. Will post back if I find any other ideas.


I am calling this a loss, going to rebuild the server but would like to keep my entire website. Other than downloading all the wordpress files, is there anything else I need to take to be able to bring this website over to my new build? Such as the sql database? If so, how is it that I obtain this database.



If your other domain resolves and access the database then it is not the server and rebuilding will only be for practice.

You may want to scuttle this wordpress install and try again.


try this

this is correct :
CREATE USER wpuser@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO wpuser@localhost;

add @localhost after username database and remove letter ' .


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct