<p>The statement uses a non-deterministic UDF, making the binary log entry unsafe and risking replica divergence.</p>
<p>MySQL Error 1672: ER_BINLOG_UNSAFE_UDF means a statement logged in STATEMENT or MIXED mode calls a user-defined function that may return different results on replicas. Switch to ROW binlog format, rewrite the UDF as DETERMINISTIC, or disable the UDF call to resolve the issue.</p>
Statement is unsafe because it uses a UDF which may not
MySQL raises Error 1672 with message "Statement is unsafe because it uses a UDF which may not return the same value on the slave" when a statement is written to the binary log under STATEMENT or MIXED mode and invokes a user-defined function (UDF) that the server deems non-deterministic.
The server marks such statements as unsafe because replicas executing them could compute a different result, causing data drift. The error halts execution when the session variable binlog_format is STATEMENT or MIXED and the session/sql_log_bin is enabled.
Unsafe statements can corrupt replication topology. A non-deterministic UDF might depend on external factors such as file IO, random values, or system time, producing different outputs on each replica. Preventing the operation preserves data consistency across masters and replicas.
The error typically surfaces during migrations, ETL jobs, or application code that calls UDFs for hashing, encryption, or custom calculations while binary logging is enabled in STATEMENT or MIXED format.
Applications may experience failed transactions or aborted migrations. Automated deployment pipelines that rely on non-deterministic UDFs can halt, requiring immediate intervention to ensure replication safety.
The CREATE FUNCTION statement omits the DETERMINISTIC clause or includes NO SQL/READS SQL DATA properties that indicate possible variability across executions.
The global or session binlog_format is not set to ROW, so MySQL must evaluate the statement rather than record row images, exposing nondeterminism.
The UDF relies on file system reads, network calls, random generators, or current timestamps, making results differ on replicas.
Bulk-load or maintenance scripts executed by DBA accounts often call utility UDFs without considering binary-log safety.
Raised when statements invoke system functions like UUID() in STATEMENT or MIXED mode, similar root cause.
A warning, not error, signaling that a statement is potentially unsafe but still logged.
Occurs when multiple-row INSERT with AUTO_INCREMENT is logged in STATEMENT mode, risking divergence.
Ignoring it in non-replicated environments is safe, but switch to ROW or disable logging before production deployment.
ROW increases binary log size but offers safer replication. Most modern setups accept the trade-off.
Query information_schema.routines for routines without DETERMINISTIC and specific SQL data access clauses.
Galaxy highlights replication-unsafe keywords, suggests ROW format, and allows team members to endorse deterministic UDF definitions, reducing runtime failures.