Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I've used the following to grant all privileges on mydb to myusername:

GRANT ALL PRIVILEGES ON mydb.* to myusername @'%' IDENTIFIED BY 'mypassword';

I thought that the % is a wildcard for all hosts. It worked for a while, but then I had some permission errors when the user tried to access the db from the same machine. I added the following lines:

GRANT ALL PRIVILEGES ON mydb.* to myusername @'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydb.* to myusername @'127.0.0.1' IDENTIFIED BY 'mypassword';

And now the user can access the database.

What does the % stand for? Is there a wildcard for all hosts?

share|improve this question
1  
I'm not sure whether a space is allowed before @. Anyway, from the docs: The simple form user_name is a synonym for user_name@'%'. So, just omit the @'hostname part. –  dezso Oct 14 '12 at 7:40
    
Thanks @dezso, care to post it as an answer? –  Adam Matan Oct 14 '12 at 9:04

1 Answer 1

up vote 1 down vote accepted

Looking up the documentation, two things to mention:

  • not sure whether a space is allowed before @ (not declared explicitly, but the user string takes the user_name@host_name form - and since this is a string, one can expect that the space is not allowed)

  • and, better, if you want to grant privileges to a user on all hosts, you can simply omit the @hostname part completely.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.