A guide to resolving MySQL permission errors when importing databases with DEFINER clauses that reference non-existent or unauthorized user accounts.
An ERROR 1227 (42000)
typically occurs during MySQL import operations when the dump file contains DEFINER
clauses referencing MySQL user accounts that either:
When MySQL attempts to create these objects using the specified DEFINER
account, it verifies the account’s existence and privileges. If the checks fail, the import results in ERROR 1227
. This commonly happens when migrating databases between different environments or servers with differing user accounts and privileges.
To resolve this error, try the following:
The simplest and safest approach is to strip all DEFINER
clauses from the dump file before importing. This causes MySQL to create objects under the importing user’s privileges instead of a potentially invalid or unauthorized DEFINER
.
You can do this with a command-line text-processing utility like sed
:
$ sed -i 's/\sDEFINER=`[^`]*`@`[^`]*`//g' yourdumpfile.sql
This regular expression matches all DEFINER
clauses and removes them in place. This ensures compatibility regardless of the users existing on the target server.
If you have control over the dump generation, create the dump without DEFINER clauses using:
<username>
, <hostname>
, <port>
and <database_name>
with your actual MySQL username, host address, and database name respectively before running the command. For security reasons, omit the password value from the command and enter it when prompted.
$ mysqldump --user="<username>" --password --host="<hostname>" --port=<port> --set-gtid-purged=OFF --databases <database_name> > vultr-db-export.sql
--set-gtid-purged=OFF
avoids GTID-related privilege statements which can cause import issues.This method prevents DEFINER
-related errors entirely by not including DEFINER
statements in the export.
Use a MySQL user with sufficient privileges, such as vultradmin
, to perform the import:
$ mysql --user=vultradmin --password --host="<hostname>" --port=<port> < vultr-db-export.sql
Admin users have the necessary SUPER
or SYSTEM_VARIABLES_ADMIN
privileges to bypass restrictions on DEFINER
clauses, allowing the import to complete successfully.