3076
MySQLERRORNotableReplicationHIGH confidence
Cannot change binlog_direct_non_transactional_updates inside a stored function or trigger
Production Risk
Medium — function or trigger execution fails entirely.
What this means
The binlog_direct_non_transactional_updates variable cannot be changed inside a stored function or trigger.
Why it happens
- 1Using SET SESSION binlog_direct_non_transactional_updates within a stored function or trigger body.
How to reproduce
trigger — this will error
trigger — this will error
CREATE FUNCTION f() RETURNS INT BEGIN SET SESSION binlog_direct_non_transactional_updates = ON; RETURN 1; END;
expected output
ERROR 3076 (HY000): Cannot change the binlog_direct_non_transactional_updates inside a stored function or trigger.
Fix
Set the variable outside the stored routine context
Set the variable outside the stored routine context
SET SESSION binlog_direct_non_transactional_updates = ON; -- Then call the function
Why this works
Session variables affecting replication must be set at the session level, not inside routines.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 3076 ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT2
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev