1644
MySQLERRORNotableReplicationHIGH confidence

Cannot change sql_log_bin inside a stored function or trigger

Production Risk

Low — the SET is rejected; routine does not execute as intended.

What this means

Attempting to set sql_log_bin within a stored function or trigger is not allowed.

Why it happens
  1. 1A stored function or trigger body contains SET sql_log_bin = 0/1.
How to reproduce
trigger — this will error
trigger — this will error
CREATE FUNCTION f() RETURNS INT
BEGIN
  SET sql_log_bin = 0;
  RETURN 1;
END;

expected output

ERROR 1644 (HY000): Cannot change the sql_log_bin inside a stored function or trigger.

Fix

Move the sql_log_bin change to the calling session

Move the sql_log_bin change to the calling session
SET sql_log_bin = 0;
SELECT f();
SET sql_log_bin = 1;

Why this works

Session-level binary log control must be managed at the session level, not inside routines.

Sources
Official documentation ↗

MySQL 8.0 — 1644 ER_STORED_FUNCTION_PREVENTS_SWITCH_SQL_LOG_BIN

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors