How to Fix MySQL Error 1674 (ER_BINLOG_UNSAFE_SYSTEM_FUNCTION)
You get mysql error 1674 when a query uses a system function during statement-based replication. You can fix it by switching to row-based logging or passing fixed values from your app. Database clusters rely on binary logs to keep data in sync across nodes. When a statement runs a function that returns local node state, the replica might get different data. MySQL blocks or flags the query to prevent silent data drift across your cluster. What triggers mysql error 1674 in your database The of
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 get mysql error 1674 when a query uses a system function during statement-based replication. You can fix it by switching to row-based logging or passing fixed values from your app.
Database clusters rely on binary logs to keep data in sync across nodes. When a statement runs a function that returns local node state, the replica might get different data. MySQL blocks or flags the query to prevent silent data drift across your cluster.
What triggers mysql error 1674 in your database
The official symbol for this alert is ER_BINLOG_UNSAFE_SYSTEM_FUNCTION, which maps to SQLSTATE HY000. MySQL displays a clear warning message when this event occurs. It says the statement is unsafe because a system function may return a different value on the replica.
This issue happens when your server writes raw statements into the binary log. In statement mode, the primary node sends the exact text of the query to the replica. The replica then runs that exact same query on its own local engine.
Some system functions read local server details like version strings, user roles, or process IDs. Other functions pull host names, thread states, or local system variables. Two servers in a cluster will have different process IDs and local states.
If an insert or update statement calls these functions, the replica calculates its own local answer. That answer will not match the value written on the primary database. Over time, this mismatch corrupts your replica data and breaks cluster consistency.
How to diagnose the unsafe query safely
Start by checking your database error logs and slow query logs to find the failing statement. Look for write queries that call built-in system functions inside data change commands. You should inspect stored procedures and triggers as well, since they often hide these calls.
Many teams make the mistake of granting broad admin rights to debug production nodes. You do not need full server rights to read query logs or test statements. Use a read-only role to inspect the query text and check the current binary log format.
MySQL Access Governance + Serverless Function Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
You should also avoid turning off binary logging just to make the error stop. Skipping the binary log creates an immediate gap between your primary database and its replicas. Instead, isolate the exact query and test it in a staging cluster with replication turned on.
How to fix ER_BINLOG_UNSAFE_SYSTEM_FUNCTION in production
The cleanest fix is to change how your database records changes in the binary log. Set your cluster to use row-based binary logging or mixed mode logging. In row mode, the primary node evaluates the system function first and logs the final row data.
The replica receives the exact value that the primary node wrote to disk. It never runs the system function on its own engine. This keeps every node in sync without requiring major changes to your app code.
If you must keep statement-based logging, you need to rewrite the query in your app. Run a separate read query first to fetch the system value on the primary node. Store that result in a standard variable inside your app logic.
Next, pass that fixed variable into your write statement as a plain text or number value. Because the query now holds a static value, the binary log records safe data. Both the primary database and the replica will write the exact same record.
When teams run manual fixes on live databases, they should still protect sensitive data. Data masking rewrites matched fields like emails, phone numbers, card numbers, and national IDs in results. Pairing safe query patterns with strict role controls keeps your production cluster stable and secure.
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 1674 stop my query from running?
It depends on your server strict mode and replication rules. Often it logs a warning, but strict settings will block the write statement completely.
Why does row-based logging fix ER_BINLOG_UNSAFE_SYSTEM_FUNCTION?
Row-based logging records the actual changed data rows instead of the raw query text. The replica writes the final result without running the unsafe system function again.
Can stored triggers cause mysql error 1674?
Yes, triggers and stored functions run inside the scope of the calling write statement. If a trigger calls a local system function under statement logging, it triggers this error.
Related guides
In this post