Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

4 Answers

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
add comment

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 http://dev.mysql.com/doc/refman/5.1/en/grant.html 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
2  
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
add comment

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

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

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
add comment

Your Answer

 
discard

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