fefe
fefe

Reputation: 9055

mysql privileges

After executing the following mysql statement to create database and giving privileges to user can't access mysql

create database my_db;
GRANT ALL PRIVILEGES ON my_db.* TO 'user'@'%' IDENTIFIED BY 'mypasswd';
GRANT SELECT ON my_db.* TO 'user'@'%' IDENTIFIED BY 'mypasswd';
FLUSH PRIVILEGES;


mysql -u user -p mypasswd drops me 
Access denied for user 'user'@'localhost'

Upvotes: 1

Views: 257

Answers (3)

BMN
BMN

Reputation: 8508

There is no space between -p and your password.

As you granted rights only for the database my_db, add the db also to connect directly to it.

mysql -u user -pmypasswd my_db

Upvotes: 0

user4035
user4035

Reputation: 23729

I tried this:

GRANT ALL ON my_db.* TO 'user'@'%' IDENTIFIED BY 'mypasswd';
FLUSH PRIVILEGES;

And afterwards

./mysql -uuser -pmypasswd

worked ok for me.

If it doesn't, try with localhost:

GRANT ALL ON my_db.* TO 'user'@'localhost' IDENTIFIED BY 'mypasswd';
FLUSH PRIVILEGES;

Upvotes: 0

Wasif
Wasif

Reputation: 522

You need to give privileges separately for user to connect from localhost. % will not work.

`GRANT ALL PRIVILEGES ON my_db.* TO 'user'@'localhost' IDENTIFIED BY 'mypasswd';
 GRANT SELECT ON my_db.* TO 'user'@'localhost' IDENTIFIED BY 'mypasswd';`

Upvotes: 1

Related Questions