DBAtlas · Database operations atlas

1592: ER_BINLOG_UNSAFE_STATEMENT: Unsafe statement written to the binary log

MySQL

What does it mean?

While using the STATEMENT-based binlog format, a statement with a nondeterministic result (one that could produce a different result on the replica) was executed. MySQL issues a warning when writing it to the binlog because there is a risk of data inconsistency between source and replica.

Why does it happen?

With binlog_format=STATEMENT: nondeterministic functions such as UUID(), SYSDATE() or USER() (NOW() replicates safely with STATEMENT), UPDATE/DELETE with LIMIT but no ORDER BY, INSERTs mixed with AUTO_INCREMENT, or certain user-defined/system functions. These statements may not produce the same result on every server.

How to fix it

Switch the binlog format to row-based (recommended; ROW has been the default since MySQL 5.7.7): binlog_format=ROW in my.cnf or SET PERSIST binlog_format = ROW; (the binlog_format variable is deprecated since 8.0.34; the change takes effect for new sessions). ROW format replicates nondeterministic statements safely. If you must stay on STATEMENT, replace nondeterministic functions/expressions with constant values and add a deterministic ORDER BY to DML with LIMIT.

Open in DBAtlas →

More from this engine