Incident Response

MySQL ERROR 1419: You do not have the SUPER privilege and binary logging is enabled

Creating a stored function or trigger fails because binary logging is on and your account is not trusted to write routines. Here is why the rule exists, when it is safe to relax it, and how to handle it on RDS and across a fleet.

· 11 min read · AG Data Team

ERROR 1419 (HY000): You do not have the SUPER privilege and binary logging is enabled appears when an account without SUPER runs CREATE FUNCTION or CREATE TRIGGER on a server that writes a binary log. Nothing is broken. MySQL is refusing to let an untrusted account create code that runs inside replicated statements. The error text already names the switch, log_bin_trust_function_creators, and calls it "less safe". The question is whether it is less safe for your server.

mysql> CREATE FUNCTION order_total(p_id INT) RETURNS DECIMAL(10,2)
    ->   DETERMINISTIC READS SQL DATA
    ->   RETURN (SELECT SUM(amount) FROM order_items WHERE order_id = p_id);
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)

When exactly it fires

In the error reference 1419 is ER_BINLOG_CREATE_ROUTINE_NEED_SUPER. The MySQL 8.4 source raises it in two places: when a stored function is created (sp.cc) and when a trigger is created (sql_trigger.cc). In both places all three conditions must be true:

Stored procedures and events are not affected, which is why CREATE PROCEDURE works for the same user. Declaring a function DETERMINISTIC does not help either. In the source, the SUPER check runs even for deterministic functions.

A related error comes from the same check: ERROR 1418, "This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration". With the default setting, a function must declare one of these characteristics. ALTER FUNCTION does not check SUPER in the 8.4 source, but it can raise 1418 when you change the characteristics of a function that is not deterministic. Note that MySQL does not verify that a function declared DETERMINISTIC really is deterministic. It trusts the creator.

The 8.4 manual and the server do not agree. The 8.4 manual says creating a function needs the SET_ANY_DEFINER privilege, which MySQL 8.2.0 introduced to replace SET_USER_ID. The 8.4 server source still checks SUPER_ACL, and the message still says SUPER. Granting SET_ANY_DEFINER alone is not enough to avoid 1419.

Step 1: check the server and your account

SELECT @@log_bin,
       @@log_bin_trust_function_creators,
       @@binlog_format;

SHOW GRANTS FOR CURRENT_USER();

The value that matters most is binlog_format. The default is ROW.

Why the rule exists

The documentation explains that the danger is statement-based logging. When a statement that calls a function is written to the binary log as SQL text, replicas and point-in-time restores run the function again. A non-deterministic function, for example one that uses UUID(), then produces different data on the replica. The replica's applier thread also runs with full privileges unless replication privilege checks are set up, so a routine could contain a statement that does something dangerous only on the replica.

With row-based logging, the binary log contains the row changes made by the function or trigger, not the call itself. That is why MySQL 8.0.34 deprecated log_bin_trust_function_creators together with binlog_format: both only matter for statement-based logging, which MySQL plans to stop supporting.

Fixes, from best to worst

  1. On ROW format, trust function creators. If binlog_format is ROW on this server and on every server that may become a source, the main risk of statement replay does not apply. Turn the check off, and persist it so it survives a restart:
    -- only after you have confirmed binlog_format = ROW
    SET PERSIST log_bin_trust_function_creators = 1;   -- survives a restart
    -- MySQL 8.0.34+ and 8.4 answer with a deprecation warning; the setting still works
    Keep in mind what the switch also does. Any account with CREATE ROUTINE or TRIGGER can now create functions and triggers. Grant those privileges only to accounts that deploy code.
  2. Deploy routines with a dedicated admin account. If you cannot change the variable, run the migrations that create functions and triggers as an account that has SUPER. SUPER is deprecated and very broad, so keep that account out of applications and use it only in the deployment pipeline.
  3. On Amazon RDS and Aurora, use the parameter group. AWS does not give the master user SUPER. AWS says to set log_bin_trust_function_creators to 1 in a custom DB parameter group attached to the instance. The default parameter group cannot be changed, and in our experience SET GLOBAL for this variable is refused on RDS. Other managed services have similar settings, so check your provider's documentation.
  4. Do not turn off the binary log to make the error go away. Starting the server with --skip-log-bin stops replication and point-in-time recovery. Running the migration with SET sql_log_bin = 0 creates the function only on this server. The replicas never get it, and the first query that calls it there fails.

What changes on large databases and fleets

On one test server, 1419 is a five-minute fix. With many servers, replicas and automated deploys, the same setting needs a policy:

SELECT routine_schema, routine_name, is_deterministic, sql_data_access, definer
FROM information_schema.routines
WHERE routine_type = 'FUNCTION'
  AND routine_schema NOT IN ('mysql', 'sys', 'information_schema', 'performance_schema')
ORDER BY routine_schema, routine_name;

Key takeaways

MySQL Errors Replication Security
Work with us

Migrations failing on routines and triggers?

We review MySQL binary logging, replication formats and privileges, and set up migration accounts that can deploy routines and triggers safely.

Get in touch More from the blog