How to Fix MySQL Error 1670 (ER_BINLOG_UNSAFE_SYSTEM_TABLE)
You trigger mysql error 1670 when a write query reads from local system log tables. You can fix it by removing log table reads from your write queries. MySQL uses the binary log to copy data changes from a primary server to replicas. The database engine flags any statement that may create different data on a replica. System tables hold local server data that does not match across machines. Reading these tables during a write operation puts data replication at risk. What causes mysql error 167
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 trigger mysql error 1670 when a write query reads from local system log tables. You can fix it by removing log table reads from your write queries.
MySQL uses the binary log to copy data changes from a primary server to replicas. The database engine flags any statement that may create different data on a replica. System tables hold local server data that does not match across machines. Reading these tables during a write operation puts data replication at risk.
What causes mysql error 1670 in your database
The database tracks this issue under the symbol ER_BINLOG_UNSAFE_SYSTEM_TABLE and state HY000. The engine triggers this warning or error when a statement touches specific local tables. These include the general log, the slow query log, and the performance_schema tables. Every database server writes its own local events to these system tables.
A primary server has a different workload than its read replicas. The general log on the primary server holds different rows than the replica log. Slow query logs also differ because server hardware and query load vary by machine. The performance_schema tables track live memory and thread stats for that single host only.
Statement-based replication copies the exact SQL query to the replica server. If an insert or update pulls data from those system tables, the replica runs it too. The replica reads its own local system tables and writes different values. Now your replica data no longer matches your primary data.
How to find the failing queries in production
First, check your database error logs and warning tables to find the exact query. Look for audit jobs or admin scripts that copy log rows into user tables. Teams often build custom monitoring scripts that save performance stats into a central table. These scripts cause the error when they run under statement-based replication.
You should also check stored routines, triggers, and scheduled database events. A trigger might log the current thread state from performance_schema during a table update. Because the trigger runs inside the main transaction, the engine marks the whole query unsafe. Finding the exact script lets you plan a clean fix.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
How to fix the error without breaking safety checks
The best fix is to split the read and write steps in your app. Have your app or monitoring tool read the system tables with a simple select query. Store those results in memory inside your app layer. Next, run a standard insert query with literal values to save that data.
Literal values in an insert query are safe for the binary log. The primary server writes the exact values into the binary log for the replica. The replica then inserts those exact same values without reading its own system tables. This keeps your data identical across the whole cluster.
You can also change how the server formats the binary log for data changes. Row-based logging records the actual changed row data instead of the raw SQL text. When the engine logs the final row values, the replica does not read system tables. Still, changing log modes affects network load and disk space across your cluster. Always test logging changes in a staging setup before you update production.
Never turn off binary logging just to make an admin script pass. Skipping the binary log on the primary server causes immediate data drift on replicas. Do not grant broad superuser permissions to app roles to bypass replication rules. Keep your roles tight and fix the query design instead.
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 1670 stop my query from running?
In statement mode, it logs a warning, or blocks the query under strict settings. Even when it only warns you, your replica data can still go out of sync.
Can I read performance_schema tables with a normal select query?
Yes, plain select queries do not write to the binary log. You can read system tables at any time as long as you do not modify data.
Why do my replicas have different data in the slow query log?
Each server runs its own local log based on its own hardware and queries. Replicas do not copy system log tables from the primary server during normal operation.
Related guides
In this post