How MySQL Handles Permissions for Views vs Base Tables
MySQL provides granular access control when working with Views. Permissions behave differently depending on whether queries run under the definer's privileges or the invoker's privileges.
Views in MySQL operate under two security modes: SQL SECURITY DEFINER (default) and SQL SECURITY INVOKER.
Under DEFINER mode, the user's permissions are not directly checked against the base tables — rather, the view runs with the privileges of the view creator.
Under INVOKER mode, the querying user must have individual privileges on both the view and the underlying base tables.
To access a view, a user must be granted at least SELECT (or INSERT/UPDATE/DELETE if applicable) on the view itself.
If the view is defined with SQL SECURITY DEFINER, the user does NOT need permissions on the base tables — only the view owner does.
If SQL SECURITY INVOKER is used, the user must have permissions on both the view and its underlying tables.
Views can hide sensitive columns by exposing only selected fields.
A user may be granted SELECT on a view without gaining SELECT on the base table.
This enables column-level and row-level security.
Example: A view that hides salary information in an employees table.
If a user attempts INSERT/UPDATE/DELETE through a view, MySQL checks whether the view is updatable and whether privileges exist.
Under DEFINER mode, the DEFINER must have table privileges for the operations to succeed.
Views cannot be used to bypass base table restrictions if the DEFINER lacks permissions.
In summary, granting privileges on a view does not automatically grant access to its underlying tables. MySQL’s SQL SECURITY modes define whose permissions apply, making views a powerful mechanism for secure, controlled data access.
0-2 years experience
2-5 years experience
5-8 years experience
8+ years experience