MySQL & MariaDB error 1449: The user specified as a definer does not exist
The user specified as a definer ('olddev'@'%') does not exist (5.6.51) · The user specified as a definer ('olddev'@'%') does not exist (10.6.28) A view, trigger, stored routine or event runs with the privileges of its DEFINER account, and that account no longer exists, typically after copying a database to another server or dropping an old user.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_NO_SUCH_USER | ER_NO_SUCH_USER |
| SQLSTATE | HY000 | HY000 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
The user specified as a definer ('olddev'@'%') does not exist. Views, triggers, procedures, functions and events default to SQL SECURITY DEFINER: they run with the privileges of the account that created them. If that account is missing, the server can’t run them, so even a plain SELECT from a view, or an INSERT that fires a trigger, fails.
Why it happens
- Restoring a dump on another server: mysqldump keeps
DEFINER='olddev'@'%', but that account doesn’t exist there. - The developer account that created the objects was dropped.
- The host part doesn’t match (
'app'@'localhost'exists, the definer is'app'@'%').
MySQL 8.0.22+ helps prevent this: DROP USER warns (4005, “referenced as a definer account”) when the account still owns objects, and our tests show that warning on MySQL 8.0–9.x. MariaDB and MySQL 5.x drop the user silently.
How to fix it
- Find affected objects:
SELECT table_name, definer FROM information_schema.VIEWS WHERE definer NOT IN (SELECT CONCAT(user, '@', host) FROM mysql.user);(and the same againstROUTINES,TRIGGERS,EVENTS). - Re-point them at an existing account:
ALTER DEFINER = CURRENT_USER VIEW v AS …(views, events), or drop and re-create triggers and routines. - Or create the missing account with the needed privileges.
- Consider
SQL SECURITY INVOKERfor views that don’t need elevated privileges.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database and the test data:CREATE DATABASE demo; USE demo; CREATE TABLE t (a INT); INSERT INTO t VALUES (1);Run:
CREATE USER 'olddev'@'%' IDENTIFIED BY 'Test#1234'; GRANT SELECT ON demo.* TO 'olddev'@'%'; CREATE DEFINER = 'olddev'@'%' SQL SECURITY DEFINER VIEW v AS SELECT a FROM t; DROP USER 'olddev'@'%'; SELECT * FROM v;
You get: The user specified as a definer ('olddev'@'%') does not exist(11.8.9)
Verified fixes
Re-create the object with an existing definer (ALTER ... DEFINER), or SQL SECURITY INVOKER
CREATE USER 'olddev'@'%' IDENTIFIED BY 'Test#1234'; CREATE DEFINER = 'olddev'@'%' SQL SECURITY DEFINER VIEW v AS SELECT a FROM t; DROP USER 'olddev'@'%'; ALTER DEFINER = CURRENT_USER SQL SECURITY INVOKER VIEW v AS SELECT a FROM t; SELECT * FROM v;Find objects whose definer no longer exists
CREATE USER 'olddev'@'%' IDENTIFIED BY 'Test#1234'; CREATE DEFINER = 'olddev'@'%' VIEW v AS SELECT a FROM t; DROP USER 'olddev'@'%'; SELECT TABLE_NAME, DEFINER FROM information_schema.VIEWS WHERE TABLE_SCHEMA = DATABASE() AND DEFINER NOT IN (SELECT CONCAT(user, '@', host) FROM mysql.user);
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| A view whose DEFINER account was dropped (common after copying a database between servers) repro | ✓ 1449 | ✓ 1449 | ✓ 1449 | ✓ 1449 | ✓ 1449 | ✓ 1449 | ✓ 1449 | ✓ 1449 | ✓ 1449 |
| Re-create the object with an existing definer (ALTER ... DEFINER), or SQL SECURITY INVOKER fix | ✓ | ✓ | ⚠ 4005 | ⚠ 4005 | ⚠ 4005 | ✓ | ✓ | ✓ | ✓ |
| Find objects whose definer no longer exists fix | ✓ | ✓ | ⚠ 4005 | ⚠ 4005 | ⚠ 4005 | ✓ | ✓ | ✓ | ✓ |
What the warnings and failures say (2)
- Re-create the object with an existing definer (ALTER ... DEFINER), or SQL SECURITY INVOKER (MySQL 8.0, MySQL 8.4, MySQL 9): warning 4005: User 'olddev'@'%' is referenced as a definer account in a view.
- Find objects whose definer no longer exists (MySQL 8.0, MySQL 8.4, MySQL 9): warning 4005: User 'olddev'@'%' is referenced as a definer account in a view.
Related errors
How the message changed between versions
| MySQL from | Symbol | Message |
|---|---|---|
| 5.0.96 | ER_NO_SUCH_USER | There is no '%-.64s'@'%-.64s' registered |
| 5.1.77 | ER_NO_SUCH_USER | The user specified as a definer ('%-.64s'@'%-.64s') does not exist |
| MariaDB from | Symbol | Message |
|---|---|---|
| 5.5.68 | ER_NO_SUCH_USER | The user specified as a definer ('%-.64s'@'%-.64s') does not exist |
| 12.0.2 | ER_NO_SUCH_USER | The user '%-.64s'@'%-.64s' does not exist |