SQL SECURITY is a clause supported by MySQL and MariaDB that controls the privilege context used when a view, stored procedure, stored function, trigger, or event executes. When set to DEFINER, the object runs with the rights of the account named in its DEFINER clause, regardless of who invokes it. When set to INVOKER, the object runs with the rights of the current session user. The clause strengthens security by limiting or extending access in a controlled way and prevents accidental privilege escalation. If SQL SECURITY is omitted, MySQL defaults to DEFINER for routines, triggers, and events, and to DEFINER for views unless explicit default settings have been changed. Only users with the SUPER or SET_USER_ID privilege can create objects with a DEFINER other than themselves. Changes to the DEFINER account (for example, dropping it) can make objects that use SQL SECURITY DEFINER become unusable.
DEFINER
(keyword) - Executes the object with the privileges of the account named in the DEFINER clause.INVOKER
(keyword) - Executes the object with the privileges of the session user who calls or fires the object.DEFINER clause, INVOKER rights, CREATE VIEW, CREATE PROCEDURE, SECURITY DEFINER (PostgreSQL)
MySQL 5.0 (views) and 5.0.13 (routines)
MySQL defaults to DEFINER for views, routines, triggers, and events. The object runs with the creator's rights unless a different DEFINER is specified.
Yes. Use ALTER VIEW, ALTER PROCEDURE, or ALTER EVENT with a new SQL SECURITY clause to switch between DEFINER and INVOKER.
Only users with the SUPER or SET_USER_ID privilege can create or alter an object with a DEFINER that is not themselves.
The object becomes invalid. Attempts to invoke it will raise error 1449: The user specified as a DEFINER does not exist.