Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i want to import a very large sql file.So I am using the following command

mysql -u username -p  dbname < something.sql

and when it prompts for password i give the password...

then it throws an error like this

ERROR 1044 (42000) at line 21: Access denied for user 'username'@'localhost' to database 'db'

I used the grant command and gave permissions using control panel too...still getting the same error..

any idea why it is throwing this error??Please help me..

share|improve this question
In your example you have "dbname" in your example command and "db" in the error -- are they actually the same? – Craig Oct 2 '09 at 8:10

You need to be quite clear about the GRANT command. If you granted it using 'username'@'localhost', it can only be used by a mysql running locally with the database. If you granted it using 'username'@'%', it can only be used from a remote location, not the local machine.

share|improve this answer
Actually you should be able to connect from the local machine if you simply add the -h parameter when connecting. – Zoredache Oct 2 '09 at 6:38

your user has no permission to connect to that database. Or simply does not exist in that form. You can create it and grant permissions at the same time. Check out the page, search for "IDENTIFIED BY " keywords.

share|improve this answer
i used the grant command too...and also gave all permissions using control panel...its still giving the same error..:/ – someone Oct 2 '09 at 6:04
and you are sure you used grant with 'username'@'localhost' and not just 'username' or something like that? – monomyth Oct 2 '09 at 6:18

You probably need to "flush privileges" after the grant.

share|improve this answer
There's no need to FLUSH when using GRANT/CREATE. – Dan Carley Oct 2 '09 at 6:53

You probably ran the grant incorrectly, it should look something like this:

GRANT ALL PRIVILEGES ON dbname.* TO username@localhost IDENTIFIED BY 'mysecretpassword'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.