Common SQL Errors

MySQL Error 1672: ER_BINLOG_UNSAFE_UDF - How to Fix Unsafe UDF Binary Logging Issues

Galaxy Team
August 7, 2025

<p>The statement uses a non-deterministic UDF, making the binary log entry unsafe and risking replica divergence.</p>

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL Error 1672 ER_BINLOG_UNSAFE_UDF?

<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>

Error Highlights

Typical Error Message

Statement is unsafe because it uses a UDF which may not

Error Type

Replication / Binary Logging Error

Language

MySQL

Symbol

ER_BINLOG_UNSAFE_UDF

Error Code

1672

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1672: ER_BINLOG_UNSAFE_UDF?

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.

Why does the error matter?

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.

When does it usually appear?

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.

Impact on applications

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.

Common Causes

Non-deterministic UDF Definition

The CREATE FUNCTION statement omits the DETERMINISTIC clause or includes NO SQL/READS SQL DATA properties that indicate possible variability across executions.

STATEMENT or MIXED Binlog Format

The global or session binlog_format is not set to ROW, so MySQL must evaluate the statement rather than record row images, exposing nondeterminism.

External State Dependency

The UDF relies on file system reads, network calls, random generators, or current timestamps, making results differ on replicas.

Superuser Import Scripts

Bulk-load or maintenance scripts executed by DBA accounts often call utility UDFs without considering binary-log safety.

Related Errors

MySQL Error 1592: ER_BINLOG_UNSAFE_SYSTEM_FUNCTION

Raised when statements invoke system functions like UUID() in STATEMENT or MIXED mode, similar root cause.

MySQL Warning 1722: ER_BINLOG_UNSAFE_WARNING

A warning, not error, signaling that a statement is potentially unsafe but still logged.

MySQL Error 1665: ER_BINLOG_UNSAFE_AUTOINC_COLUMNS

Occurs when multiple-row INSERT with AUTO_INCREMENT is logged in STATEMENT mode, risking divergence.

FAQs

Can I ignore Error 1672 in development?

Ignoring it in non-replicated environments is safe, but switch to ROW or disable logging before production deployment.

Does ROW format have performance costs?

ROW increases binary log size but offers safer replication. Most modern setups accept the trade-off.

How do I find non-deterministic UDFs?

Query information_schema.routines for routines without DETERMINISTIC and specific SQL data access clauses.

How does Galaxy help prevent this error?

Galaxy highlights replication-unsafe keywords, suggests ROW format, and allows team members to endorse deterministic UDF definitions, reducing runtime failures.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo