MySQL RDS – Remove DEFINER from Stored Procedures

You could occasionally get the following problem when working with triggers or moving data between RDS instances.

“ERROR 1419 (HY000): You do not have the SUPER privilege and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)”

In these cases, alter the log_bin_trust_function_creators value in the custom DB parameter group to 1.

This allows functions, procedures, and triggers on your DB instance.

However, when you try to dump the databases you’ll get a similar error since certain statements, like “SET @@SESSION.SQL_LOG_BIN= 0;” that are typically found in MySQL dump files aren’t supported by RDS. Before running the dump file against the RDS instance, these lines in the file should be removed or commented on.

The following example explains how the DEFINER can be removed in Linux, macOS, or Windows Subsystem for Linux (WSL):

Just to remove the “DEFINER”, use the following command.
sed -i -e ‘s/DEFINER=`root`@`localhost`//g’ dump.sql

In order to find and replace with a different user, use the following command.
sed -i -e ‘s/DEFINER=`root`@`localhost`/DEFINER=`masteruser`@`%`/g’ dump.sql

Note: Replace the value for “masteruser” with the name of your Amazon RDS master user.

Credits: AWS Knowledge Centre.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s