mysql forgets who is logged in: command denied to user ''@'%'

The issue is probably that you have VIEWS in your database. The views are probably created with specific rights.

As you can tell by your error message, it complains about a different user than the one you are logged in is. This is because for a view you can specify how to determine what rights the view has to look at data.

When you go to your database, try typing:

SHOW FULL TABLES IN sunflower_work WHERE TABLE_TYPE NOT LIKE '%table%';

Then you may wish to look into the rights of the specific views that are there.


The answers here helped me with my specific problem. Many thanks! A view was the culprit as described above.

I got into trouble because the database in question was created from a backup of a remote database which had different users. The 'broken' view was 'defined' by a user I didn't have locally. Even root was unable to run the crashing query.

Changed the view's 'DEFINER' to a valid local user and the problem was solved!

ALTER 
DEFINER = 'a_valid_user'@'localhost' 
VIEW my_view
AS 
SELECT ..... 

Check out ALTER VIEW documentation for MySQL 5.5

Many thanks again!


Take schema backup before proceeding.

If you just imported a dump file in mysql, delete that import and related schema and start again.

open the dump file in a text editor and delete all lines with the following content /*! ~~~~ DEFINER='root' @'%' SQL SECURITY DEFINER */

~ Represents a random number generated by workbench during export

This solution is a quick fix and intended for development environments only.

Tags:

Mysql