1643
MySQLERRORNotableReplicationHIGH confidence

Cannot change sql_log_bin inside an active transaction

Production Risk

Medium — the SET is rejected; but pattern of disabling binlog mid-transaction is dangerous.

What this means

The sql_log_bin session variable cannot be toggled while an active transaction is in progress, because doing so could cause part of a transaction to be omitted from the binary log.

Why it happens
  1. 1SET sql_log_bin = OFF/ON executed after BEGIN inside a transaction.
How to reproduce
trigger — this will error
trigger — this will error
BEGIN;
SET sql_log_bin = 0;
-- ERROR 1643

expected output

ERROR 1643 (HY000): Cannot change the sql_log_bin inside a transaction.

Fix

Toggle sql_log_bin outside the transaction

Toggle sql_log_bin outside the transaction
SET sql_log_bin = 0;
BEGIN;
-- your statements
COMMIT;
SET sql_log_bin = 1;

Why this works

Changing the flag outside the transaction boundary ensures consistent binary log coverage.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1643 ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SQL_LOG_BIN

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

← All MySQL errors