Grant a user permission to only view a MySQL view and nothing else

Nelson picture Nelson · Jun 24, 2010 · Viewed 87.8k times · Source

This question was originally using MySQL 5.1.44, but is applicable to MySQL 8.0+ too.

Let's say I have a table with records inserted by different users of my application. How can I give a specific user access to only see his/her records in that table? I've thought about creating a VIEW with his/her records, but I don't know how to create a MySQL user that can only see that VIEW.

So, is it possible to create a MySQL user that only has access to a single VIEW? Can this user also be made so they read-only access to that VIEW?

Thanks!

PS: What I call users in my example are really subsidiary offices that want to access their records with their own applications.

Answer

Naktibalda picture Naktibalda · Jun 24, 2010

GRANT SELECT ON database1.view1 TO 'someuser'@'somehost';