0

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..

1
  • In your example you have "dbname" in your example command and "db" in the error -- are they actually the same?
    – Craig
    Oct 2, 2009 at 8:10

4 Answers 4

1

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.

1
  • Actually you should be able to connect from the local machine if you simply add the -h parameter when connecting.
    – Zoredache
    Oct 2, 2009 at 6:38
0

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.

2
  • i used the grant command too...and also gave all permissions using control panel...its still giving the same error..:/
    – someone
    Oct 2, 2009 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, 2009 at 6:18
0

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

1
  • 1
    There's no need to FLUSH when using GRANT/CREATE.
    – Dan Carley
    Oct 2, 2009 at 6:53
0

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

GRANT ALL PRIVILEGES ON dbname.* TO username@localhost IDENTIFIED BY 'mysecretpassword'

You must log in to answer this question.