MySQL 8.4Lab-verified · 2026-11-29

MySQL ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER or SET_ANY_DEFINER privilege(s) for this operation

A normal account tried something only an admin may do: set another user as DEFINER, or change a global variable.

MySQL 8.4.13
1227 (42000): Access denied; you need (at least one of) the SUPER or SET_ANY_DEFINER privilege(s) for this operation

Jump to a cause

  1. 01Importing a view with DEFINER set to another user
  2. 02Creating a procedure with DEFINER set to another user
  3. 03SET GLOBAL from a normal account

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-29 · container image mysql:8.4

ERROR 1227 means the statement needs an admin-level privilege. The message names which one: SET_ANY_DEFINER when the statement sets someone else as DEFINER, SYSTEM_VARIABLES_ADMIN for SET GLOBAL. SUPER is always listed as the alternative.

Below, account lab_a (ALL on database lab_a, nothing global) hits the error three ways. In every case the fix did not add privileges: the statement was changed so it only touches what lab_a itself owns.

01Importing a view with DEFINER set to another user

Views in a dump from another server usually come as CREATE ALGORITHM=UNDEFINED DEFINER=admin@% SQL SECURITY DEFINER VIEW …. Running that as lab_a failed with ERROR 1227 and SUPER or SET_ANY_DEFINER, because lab_a is not admin.

SELECT CURRENT_USER() showed lab_a@%. With only the DEFINER=… part removed, the view was created, information_schema.VIEWS showed the DEFINER as lab_a@%, and the view returned 3500.

Setup
Setuprun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY, amount INT);
INSERT INTO orders VALUES (1, 1000), (2, 2500);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
CREATE ALGORITHM=UNDEFINED DEFINER=`admin`@`%` SQL SECURITY DEFINER VIEW v_order_total AS
SELECT SUM(amount) AS total FROM orders;
✕ ERROR
ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER or SET_ANY_DEFINER privilege(s) for this operation
Checkrun as lab_a
SELECT CURRENT_USER();
OUTPUT
+----------------+
| CURRENT_USER() |
+----------------+
| lab_a@%        |
+----------------+
1 row in set (0.00 sec)

Removing the DEFINER clause makes the current account the definer. Do this before importing when the original definer does not exist on the target or you cannot use it.

After the fixrun as lab_a
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW v_order_total AS
SELECT SUM(amount) AS total FROM orders;
SELECT TABLE_NAME, DEFINER FROM information_schema.VIEWS WHERE TABLE_SCHEMA = DATABASE();
SELECT * FROM v_order_total;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

+---------------+---------+
| TABLE_NAME    | DEFINER |
+---------------+---------+
| v_order_total | lab_a@% |
+---------------+---------+
1 row in set (0.00 sec)

+-------+
| total |
+-------+
|  3500 |
+-------+
1 row in set (0.00 sec)

02Creating a procedure with DEFINER set to another user

Stored procedures are checked the same way. CREATE DEFINER=admin@% PROCEDURE order_count() … failed with the same ERROR 1227.

SHOW GRANTS FOR 'lab_a'@'%' showed only USAGE ON *.* and ALL PRIVILEGES ON lab_a.*. ALL on its own database is not enough to name another definer. With DEFINER=CURRENT_USER the procedure was created and CALL order_count() returned 2.

Setup
Setuprun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY, amount INT);
INSERT INTO orders VALUES (1, 1000), (2, 2500);
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
CREATE DEFINER=`admin`@`%` PROCEDURE order_count()
SELECT COUNT(*) AS cnt FROM orders;
✕ ERROR
ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER or SET_ANY_DEFINER privilege(s) for this operation
Checkrun as root
SHOW GRANTS FOR 'lab_a'@'%';
OUTPUT
+--------------------------------------------------+
| Grants for lab_a@%                               |
+--------------------------------------------------+
| GRANT USAGE ON *.* TO `lab_a`@`%`                |
| GRANT ALL PRIVILEGES ON `lab_a`.* TO `lab_a`@`%` |
+--------------------------------------------------+
2 rows in set (0.00 sec)
After the fixrun as lab_a
CREATE DEFINER=CURRENT_USER PROCEDURE order_count()
SELECT COUNT(*) AS cnt FROM orders;
CALL order_count();
✓ SUCCESS
Query OK, 0 rows affected (0.01 sec)

+-----+
| cnt |
+-----+
|   2 |
+-----+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

03SET GLOBAL from a normal account

SET GLOBAL sql_mode = … from lab_a failed with ERROR 1227, this time naming SUPER or SYSTEM_VARIABLES_ADMIN. @@GLOBAL.sql_mode stayed at the default value.

When the change is only needed for your own connection, SET SESSION sql_mode = … works without extra privileges. The check showed session_changed = 1 and global_changed = 0.

Reproducerun as lab_a
SET GLOBAL sql_mode = CONCAT(@@sql_mode, ',NO_UNSIGNED_SUBTRACTION');
✕ ERROR
ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation
Checkrun as lab_a
SELECT @@GLOBAL.sql_mode AS global_mode;
OUTPUT
+-----------------------------------------------------------------------------------------------------------------------+
| global_mode                                                                                                           |
+-----------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
+-----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

SET SESSION only affects the current connection. A server-wide change needs an admin account.

After the fixrun as lab_a
SET SESSION sql_mode = CONCAT(@@sql_mode, ',NO_UNSIGNED_SUBTRACTION');
SELECT @@SESSION.sql_mode LIKE '%NO_UNSIGNED_SUBTRACTION%' AS session_changed,
       @@GLOBAL.sql_mode LIKE '%NO_UNSIGNED_SUBTRACTION%' AS global_changed;
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

+-----------------+----------------+
| session_changed | global_changed |
+-----------------+----------------+
|               1 |              0 |
+-----------------+----------------+
1 row in set (0.00 sec)

FAQ

How do I fix ERROR 1227 when importing a mysqldump file?

Look for DEFINER= in the views, procedures, functions and triggers of the dump. If it names a user you are not, remove the DEFINER clause or change it to CURRENT_USER. On this page both versions worked for lab_a.

What is SET_ANY_DEFINER in MySQL?

It is the privilege the error message asks for when a statement sets another account as DEFINER (MySQL 8.4 output). This page did not grant it; it removed the DEFINER instead.

Why does SET GLOBAL give ERROR 1227?

Changing a global variable needs SYSTEM_VARIABLES_ADMIN or SUPER. If the setting is only for your connection, use SET SESSION, which worked here for lab_a without changing the global value.

I have ALL PRIVILEGES on my database. Why still ERROR 1227?

ALL on db.* covers objects in that database, not global privileges like SET_ANY_DEFINER or SYSTEM_VARIABLES_ADMIN. SHOW GRANTS showed exactly that for lab_a.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13