How to Fix MySQL Error 1715 (ER_BINLOG_UNSAFE_INSERT_SELECT_UPDATE)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 1715 when an insert query reads rows and updates duplicate keys. You fix it by sorting the read rows or changing the binary log format. MySQL flags this warning under the symbol ER_BINLOG_UNSAFE_INSERT_SELECT_UPDATE and state HY000. The engine blocks or warns about queries that can break replica servers. When the source server and replica read rows in different orders, data drifts apart. Database teams must fix this fast to keep primary and replica nodes in sync. What caus

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 1715 when an insert query reads rows and updates duplicate keys. You fix it by sorting the read rows or changing the binary log format.

MySQL flags this warning under the symbol ER_BINLOG_UNSAFE_INSERT_SELECT_UPDATE and state HY000. The engine blocks or warns about queries that can break replica servers. When the source server and replica read rows in different orders, data drifts apart. Database teams must fix this fast to keep primary and replica nodes in sync.

What causes mysql error 1715 in the database engine

MySQL uses the binary log to send data changes from primary servers to replicas. It is also used to restore data from a backup file. In statement mode, the server writes the exact query text into the binary log. Each replica then reads that log and runs the same query on its data.

This error triggers when a query inserts rows from a select statement and updates duplicates. The official engine message explains why this pattern is risky for statement replication. It states that the query is unsafe because the read order determines what updates. Without a strict sort rule, two servers can read the same source table differently.

Storage engines store rows based on page splits, index changes, and disk space. A primary server might read row A before row B during the query run. If both rows match the same unique key, row B overwrites row A. A replica might store those rows in a different physical order on its disk. The replica then reads row B first and lets row A overwrite it.

Now the primary database and the replica hold different values for the same key. The database cannot promise that both servers will reach the same final state. To protect data integrity, MySQL throws code 1715 to warn the operator or app. If strict replication checks are active, the engine stops the query from running.

How to diagnose and fix the failure in production

First, find the exact query that triggers the warning in your database error logs. Check your app code or batch jobs for insert queries that pull from tables. Look for queries that also update existing rows when they hit a duplicate key. These combined queries are the exact ones that trigger the 1715 engine rule.

MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You can fix the query itself by adding a clear sort order to it. Sort the source rows by their primary key or a unique column every time. When the select part has a unique sort order, every server reads rows identically. The primary server and all replicas will update the duplicate keys in one sequence.

Another safe fix is to split the single complex query into two separate steps. First, read the needed rows into your app or a temporary table with keys. Second, run a clean update or insert step using those clear, sorted values. This removes the guesswork for the database engine and stops the log warning.

You can also change how the database writes changes to the binary log. Switch the binary log mode from statement logging to row logging or mixed logging. In row mode, the primary server logs the actual changed data rows, not queries. Replicas just write the final row values without running the tricky select query again.

Do not fix this problem by turning off binary logging or silencing warnings. Turning off logs breaks your disaster recovery plan and blinds your replica servers. Also, do not grant extra admin rights to app roles to bypass engine checks. Fix the query order or use row logging so your data stays safe everywhere.

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 1715 stop my query or just log a warning?

By default, MySQL logs a warning and still runs the unsafe query in statement mode. If you turn on strict consistency rules, the engine blocks the query and fails.

Why does row logging stop the ER_BINLOG_UNSAFE_INSERT_SELECT_UPDATE error?

Row logging writes the final changed row values directly into the binary log file. Replicas copy those exact values instead of running the unsorted select query on their own.

Can an index fix the read order without changing the query?

No, an index alone does not force the engine to read rows in one order. You must sort the read query on a unique key to make the order predictable.

The query runs. The emails stay hidden.