How to Fix MySQL Error 1672 (ER_BINLOG_UNSAFE_UDF)
You see mysql error 1672 when a query runs an unsafe custom function during replication. You can fix this issue by switching your binary log to row format. Database engines rely on binary logs to copy changes from a primary node to replicas. When a statement uses a custom function, the replica might compute a different result. The database flags this risk with symbol ER_BINLOG_UNSAFE_UDF and state HY000. What causes mysql error 1672 in your database MySQL gives you a clear warning message wh
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You see mysql error 1672 when a query runs an unsafe custom function during replication. You can fix this issue by switching your binary log to row format.
Database engines rely on binary logs to copy changes from a primary node to replicas. When a statement uses a custom function, the replica might compute a different result. The database flags this risk with symbol ER_BINLOG_UNSAFE_UDF and state HY000.
What causes mysql error 1672 in your database
MySQL gives you a clear warning message when this event occurs. It says the statement is unsafe because it uses a user-defined function. That function may not return the same value on the replica.
This problem happens when your database uses statement-based logging. In this mode, the primary server writes the exact query text into the binary log. The replica reads that log and runs the same query text on its own data.
User-defined functions are custom extensions compiled outside the standard database engine. The engine cannot check if these custom functions are deterministic. A function might pull external system data, random values, or local time from the host. If the replica runs that function later, it writes different values into its tables. Your primary database and replica then drift apart without a hard crash.
Mixed logging mode can also trigger this warning under specific conditions. The engine tries to switch from statement logging to row logging when it sees unsafe calls. Yet complex queries or session rules can still force the warning into your error log.
How to diagnose the unsafe query in production
First, check your database error logs and client warning output to find the exact query. Look for data changes that call custom functions inside insert, update, or delete statements. Read queries do not write to the binary log, so they never trigger this alert.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Next, check which binary log format your primary server and active sessions use. Many older setups default to statement format to save disk space on the host. You should also review the source logic of the custom function with your engineering team. Check if the function depends on host files, network calls, or local memory states.
How to fix the replication warning safely
The safest fix is to set your binary log format to row mode. Row-based logging does not send the query text to the replica server. Instead, the primary node runs the custom function first and captures the final row data. It writes the exact row changes into the binary log for the replica to copy. This ensures both servers hold the exact same table data at all times.
You can also change how the app runs the custom function. Have the app call the function in a read query first and store the result. Then pass that plain value into your write query as a simple constant. The binary log records the plain value, and the unsafe warning goes away.
Do not fix this problem by turning off binary logging or granting broad admin rights. Skipping the binary log breaks your replicas and ruins your point-in-time backup plan. Keep strict role controls in place while you update your logging mode or query logic.
Check MySQL queries and results on the wire
MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.
Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.
Frequently asked questions
Does mysql error 1672 stop my query from running?
In most setups, code 1672 acts as a warning rather than a hard stop. Still, strict session rules can turn warnings into fatal errors that block the write.
Why does my custom function cause replication drift?
Custom functions run compiled code that the database engine cannot inspect or control. If that code reads host state or time, the replica gets a different result.
Will row-based logging use more disk space on the server?
Yes, row logging records every changed row instead of one short query string. Big batch updates will write more data to the binary log file.
Related guides
In this post