3085
MySQLERRORNotableReplicationHIGH confidence
Cannot change sql_log_bin inside a stored function or trigger
Production Risk
High — trigger/function fails and the DML is rolled back.
What this means
The sql_log_bin session variable cannot be changed from within a stored function or trigger.
Why it happens
- 1SET SESSION sql_log_bin used inside a stored function or trigger body.
How to reproduce
trigger — this will error
trigger — this will error
CREATE TRIGGER trg BEFORE INSERT ON t FOR EACH ROW SET SESSION sql_log_bin = 0;
expected output
ERROR 3085 (HY000): Cannot change the sql_log_bin inside a stored function or trigger.
Fix
Set sql_log_bin at the session level before invoking the routine
Set sql_log_bin at the session level before invoking the routine
SET SESSION sql_log_bin = 0; INSERT INTO t VALUES (1); SET SESSION sql_log_bin = 1;
Why this works
Session-level control outside the trigger avoids the restriction.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 3085 ER_STORED_FUNCTION_PREVENTS_SWITCH_SQL_LOG_BIN2
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev