ERROR 1449 (HY000): The user specified as a definer ('...'@'...') does not exist means you used a view, stored routine, trigger or event whose DEFINER names a MySQL account that is not on this server. The object is now an orphan. In most cases nothing is wrong with your query: the object was created by a user who has since been dropped, or the schema was restored from a dump taken on another server.
mysql> SELECT * FROM shop.order_summary;
ERROR 1449 (HY000): The user specified as a definer ('deploy'@'10.0.%') does not exist
In the server error reference this is ER_NO_SUCH_USER, number 1449, SQLSTATE HY000. The account in the message is exactly the one you need to look for, host part included.
Why a missing account breaks the object
Every view and stored program has a DEFINER. Views, procedures and functions also have SQL SECURITY, which defaults to DEFINER: the object runs with the privileges of the definer account, not of the person calling it. Triggers and events have no such option and always run in definer context. According to the stored object access control documentation:
- a routine with
SQL SECURITY DEFINERfails at execution time if the definer does not exist; - a view with
SQL SECURITY DEFINERfails whenever it is referenced; - an event fails when it is due to run;
- for a trigger, the behaviour of privilege checking is undefined. In our experience you usually see 1449 on the
INSERTorUPDATEthat fires it, which is confusing, because the statement does not mention any view or routine.
Watch the host part. MySQL accounts are user plus host, so 'deploy'@'%' existing does not help an object defined by 'deploy'@'10.0.%'. The same rule causes many "access denied for user" errors.
How objects become orphans
- Restore on another server. Dumps keep the
DEFINERclause of every view, routine, trigger and event. Load them where that account was never created and every such object is an orphan from the first minute. - The account was dropped or renamed. Since MySQL 8.0.22,
DROP USERandRENAME USERrefuse to orphan objects and fail with error 4006, Operation ... failed for ... as it is referenced as a definer account. On older versions, or when someone overrides the check, the drop just succeeds. - The object was created with a non-existent definer on purpose. A user with
SET_ANY_DEFINERcan name any account; if it does not exist, MySQL only gives a warning.
Find every orphan at once
Do not fix them one error at a time. The definer of each object is in INFORMATION_SCHEMA, in user@host form, so one query compares them all with mysql.user:
-- every stored object whose definer account no longer exists
SELECT * FROM (
SELECT 'VIEW' AS type, TABLE_SCHEMA AS db, TABLE_NAME AS name, DEFINER
FROM information_schema.VIEWS
UNION ALL
SELECT ROUTINE_TYPE, ROUTINE_SCHEMA, ROUTINE_NAME, DEFINER
FROM information_schema.ROUTINES
UNION ALL
SELECT 'TRIGGER', TRIGGER_SCHEMA, TRIGGER_NAME, DEFINER
FROM information_schema.TRIGGERS
UNION ALL
SELECT 'EVENT', EVENT_SCHEMA, EVENT_NAME, DEFINER
FROM information_schema.EVENTS
) o
WHERE o.DEFINER NOT IN (SELECT CONCAT(User, '@', Host) FROM mysql.user)
ORDER BY db, type, name;
For each row, decide: should this account exist, or should the object belong to someone else?
Fix 1: re-create the account
If the account was dropped by mistake and the objects should keep working exactly as before, create it again with the privileges the objects need. There is a trap here. Since 8.0.22, CREATE USER also fails if the new account is named as the definer of an orphaned object, because the account would silently "adopt" those objects. To do it anyway you need ALLOW_NONEXISTENT_DEFINER on MySQL 8.2 and later, or SET_USER_ID on 8.0. The MySQL 8.2.0 release notes split SET_USER_ID into SET_ANY_DEFINER and ALLOW_NONEXISTENT_DEFINER; SET_USER_ID was deprecated in 8.2.0 and removed in 8.4.0.
Think before you re-create an old account just to silence the error. Every orphaned object with that definer becomes runnable with its privileges, including ones you forgot about.
Fix 2: change the definer
Usually the better fix is to give the objects to a real, dedicated owner account. How you do it depends on the type:
- Views: ALTER VIEW accepts
DEFINER, but you must repeat the wholeSELECT. - Events: ALTER EVENT can change just the definer.
- Procedures, functions, triggers: there is no way to change the definer in place. Drop and re-create them from
SHOW CREATE.
-- views: ALTER VIEW needs the full SELECT, take it from SHOW CREATE VIEW
SHOW CREATE VIEW shop.order_summary\G
ALTER DEFINER = 'app_owner'@'10.0.%' SQL SECURITY DEFINER
VIEW shop.order_summary AS
SELECT ...; -- the original SELECT, unchanged
-- events: only the definer changes
ALTER DEFINER = 'app_owner'@'10.0.%' EVENT shop.purge_sessions;
-- procedures and functions: no ALTER ... DEFINER, so drop and re-create
SHOW CREATE PROCEDURE shop.close_month\G
DROP PROCEDURE shop.close_month;
CREATE DEFINER = 'app_owner'@'10.0.%' PROCEDURE shop.close_month(...)
...; -- the original body
-- or, if the routine can run with the caller's privileges:
ALTER PROCEDURE shop.close_month SQL SECURITY INVOKER;
-- triggers: drop and re-create, with a short metadata lock wait
SET SESSION lock_wait_timeout = 5;
SHOW CREATE TRIGGER shop.orders_bi\G
DROP TRIGGER shop.orders_bi;
CREATE DEFINER = 'app_owner'@'10.0.%' TRIGGER shop.orders_bi
BEFORE INSERT ON shop.orders FOR EACH ROW
...; -- the original body
Switching a routine to SQL SECURITY INVOKER with ALTER PROCEDURE (or ALTER FUNCTION), or a view with ALTER VIEW ... SQL SECURITY INVOKER, avoids the error without re-creating anything, but it changes the security model: the code now runs with the caller's privileges. That is often what you want, but check that callers have every privilege the body needs.
Use a dedicated owner account. Do not set the definer to root or to a personal admin login. A definer-context object runs with all of its definer's privileges, whoever calls it, and personal accounts are exactly the ones that get dropped when someone leaves.
Stop the next migration from doing it again
mysqldump has no option to drop DEFINER clauses. Either create the definer accounts on the target before you load, or rewrite the definers in the dump. MySQL Shell's dump utilities have a strip_definers compatibility option: it removes the DEFINER clause from views, routines, events and triggers and switches views and routines to SQL SECURITY INVOKER. That changes behaviour too, so check that the application accounts have the privileges the code needs. Our comparison of mysqldump and XtraBackup covers which tool fits which migration.
After every restore, run the orphan query above before the application goes live.
On large production servers
Fixing one view on a test server takes a minute. On a production server with hundreds of objects and steady traffic, plan for these:
- Generate the fixes, do not type them. Build the statements from the orphan query and
SHOW CREATEoutput, run them on a staging copy first, and compare object counts before and after. - Re-creating a trigger leaves a gap. Between
DROP TRIGGERandCREATE TRIGGER, rows written to the table do not fire it. On a busy table with an audit or denormalisation trigger, do it in a quiet window, or plan to fix up the rows written in between. - Metadata locks.
DROPandCREATE TRIGGERneed a metadata lock on the table and wait behind any long transaction that touched it; everything queued behind them waits too. The default lock_wait_timeout is one year. Set it to a few seconds in the session that runs the fix and retry on timeout. - Replicas. DDL replicates, so fix definers on the source. With row-based replication, triggers do not run on the replica, so an orphaned trigger there does not break replication, but it will break the day that replica is promoted. Run the orphan query on replicas too.
- Events fail quietly. An orphaned event does not raise an error to any client. It fails on schedule, and the Event Scheduler writes the error to the server error log. If a nightly purge has stopped working after a migration, check the definer first.
Key takeaways
- Error 1449 means a view, routine, trigger or event has a
DEFINERaccount that does not exist, host part included. - Find every orphan with one query against
INFORMATION_SCHEMAandmysql.user. - Views and events can change definer with
ALTER; routines and triggers must be dropped and re-created. - Re-creating the old account works, but since 8.0.22 it needs
ALLOW_NONEXISTENT_DEFINER(8.2+) orSET_USER_ID(8.0). - Check definers after every restore, and use a dedicated owner account instead of personal logins.