1622
MySQLWARNINGNotableReplicationHIGH confidence

Statement using system variable is unsafe for statement-based replication

Production Risk

Medium — system variable values may differ between master and replica.

What this means

A statement reads a system variable whose value may differ between master and replica, making the statement unsafe in STATEMENT binlog mode.

Why it happens
  1. 1The query references a system variable like @@hostname or @@server_id that can differ per server.
  2. 2Session-level variables are set differently on master and replica.
How to reproduce
trigger — this will error
trigger — this will error
INSERT INTO log_table VALUES (@@hostname, NOW());

expected output

Warning 1622: Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.

Fix

Use ROW binlog format

Use ROW binlog format
SET SESSION binlog_format = 'ROW';

Why this works

ROW format captures actual data values, not the statement, avoiding system variable divergence.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1622 ER_BINLOG_UNSAFE_SYSTEM_VARIABLE

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

← All MySQL errors