Sunday, March 12, 2017

mysql - select query denied error

select command denied to user ''@'' for table ''

Solution :

You are getting this error because you are logged into the mysql user account where Select_priv is set as N for the user.

If you are able to modify your own privileges that is really good (Generally this can't be done because of security) otherwise you need to login with super user and need to set this privilege as Y.

Run this query :

update user set Select_priv = 'Y' where User = 'username';

Changes will not take effect after running this query. You will have to flush privileges.

Run Query :

FLUSH PRIVILEGES;

After flushing privileges, if still you face denied error for select query, Log out from mysql, Log in again with same user and running select query again.
You will not get the error.

If you get same denied error for Insert, Update and Delete queries, you need to set them as Y using same method.

Restarting mysql does the job but every time you do not have command line access to restart it that's why you need to flush privileges.