When This Error Shows Up
You're restoring a MySQL dump from one server to another, maybe from a production box to a local dev environment. Everything runs fine until you hit: ERROR 1227 (42000) at line X: Access denied; you need (at least one of) the SUPER privilege(s) for this operation. Or maybe you're trying to create a definer on a view or a trigger, and boom — same wall.
I've seen this most often when moving databases between different MySQL versions, especially from 5.7 to 8.0, or when using mysqldump with the --routines flag. Shared hosting accounts don't have SUPER privilege, so this error pops up like a bad dream.
Root Cause in Plain English
MySQL dump files include DEFINER statements. These tell the database who created a routine (like a stored procedure, function, trigger, or event). When you restore that dump, MySQL checks if the user running the restore has the SUPER privilege — because changing the definer requires that power.
If you don't have SUPER (common on cloud providers like AWS RDS, Google Cloud SQL, or shared hosting), MySQL says no. The tripwire is usually at a line like: DEFINER=`admin`@`%` or DEFINER=`root`@`localhost`.
The Fix – Step by Step
Three ways to beat this. Pick the one that fits your situation.
Option 1: Remove DEFINER Statements from the Dump (Best for Most)
This is the cleanest fix. Use sed or a text editor.
- Open the dump file in a text editor (like Notepad++, VS Code, or vim).
- Search for
DEFINER— you'll see lines like/*!50013 DEFINER=`root`@`localhost`*/orDEFINER=`admin`@`%`. - Replace them with nothing. In vim:
:%s/DEFINER[^ ]*//g - Save the file, then try the restore again:
mysql -u username -p database_name < dump.sql
On Linux or Mac, one-liner in terminal: sed 's/DEFINER[^ ]*//g' dump.sql > fixed_dump.sql.
Option 2: Grant SUPER Privilege (Only If You Have Root Access)
If you control the MySQL server, grant SUPER to your user. But this is rare — most hosts won't give it.
GRANT SUPER ON *.* TO 'your_user'@'localhost';
FLUSH PRIVILEGES;
Then try the restore again. If you still get errors, check the definer in the dump — you might need to skip to Option 1 anyway.
Option 3: Use mysqldump with --skip-definer (For New Dumps)
If you're creating the dump yourself, add the --skip-definer flag so the file never includes those lines to begin with.
mysqldump -u root -p --routines --events --triggers --skip-definer database_name > clean_dump.sql
Works with MySQL 8.0. For older versions like 5.7, you might need --skip-triggers --routines and handle them separately.
What to Check If It Still Fails
Sometimes the error sticks around. Here's what to look for:
- Check the exact line number in the error message. Open the dump and go to that line. It might be a trigger or event, not a routine.
- Look for DEFINER in views. MySQL views also have definers. Search for
VIEWin the dump and check the definer. - If you're on AWS RDS, Google Cloud SQL, or similar: you absolutely cannot get SUPER. Use Option 1. Also, they might require you to set
sql_modevia a parameter group — but that's a different fight. - Try restoring without routines first. Run:
mysql -u user -p database_name < dump.sql --skip-routinesand then import routines separately after editing their definers. - Last resort: Open the dump in a text editor, find all
DEFINERlines, and replace them with a user that exists on your new server (likeDEFINER=`your_existing_user`@`localhost`). This keeps the definers but uses your credentials.
I know this error is infuriating — it's one of those that makes you want to throw your laptop. But stick with Option 1, and 9 times out of 10 you're done in five minutes.