How to Fix MySQL Error 1664 (ER_BINLOG_ROW_INJECTION_AND_STMT_ENGINE)
You get mysql error 1664 when row binary log injection hits a statement-only table. You fix it by changing the storage engine or stopping row event injection. The database server returns the symbol ER_BINLOG_ROW_INJECTION_AND_STMT_ENGINE with SQLSTATE code HY000. It blocks the query because it cannot write the change to the binary log. Your query fails before it can change any data on the server. Why mysql error 1664 happens in the database engine MySQL uses the binary log to record changes
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 1664 when row binary log injection hits a statement-only table. You fix it by changing the storage engine or stopping row event injection.
The database server returns the symbol ER_BINLOG_ROW_INJECTION_AND_STMT_ENGINE with SQLSTATE code HY000. It blocks the query because it cannot write the change to the binary log. Your query fails before it can change any data on the server.
Why mysql error 1664 happens in the database engine
MySQL uses the binary log to record changes and send them to replicas. The log supports row format, statement format, and a mix of both formats. Row format records the exact data changes for each row in a table. Statement format records the exact query text that ran on the primary server.
Some replication setups inject raw row events straight into the server binary log. A common example is a cluster node or a custom replication stream tool. At the same time, some special storage engines only allow statement logging. When row injection touches a statement-only table, the engine cannot log the write. MySQL stops the work and throws mysql error 1664 to protect your data.
If the server allowed this write, the binary log would miss the update. Downstream replicas would drift out of sync with the primary database server right away. Stopping the query keeps the primary server and all replicas in the same state.
How to find the root cause in production
First, find out which query triggered the failure in your database error log. Look at every table that the failed transaction tried to read or write. Check the storage engine type for each of those tables in the schema.
Next, check how the write arrived at the database server in the first place. Look for active replication channels, cluster links, or change data tools sending row events. You do not need full admin rights to check table types and log modes. A read-only role on the system catalog tables is enough for this check.
MySQL Access Governance + Prompt Injection Prevention: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Look for mix-ups where a cluster or stream writes to a special engine table. Keep your investigation scoped to metadata queries so you do not lock busy tables.
How to fix the binary log conflict safely
The best fix is to change the target table to a standard storage engine. Pick an engine that supports both row logging and full ACID transactions. Test this table change in a staging setup before you touch production data. Make sure your app still reads and writes to the table as expected.
If you must keep the old engine, do not send row events to it. Split the transaction so row injections only hit tables that support row logging. Move the statement-only table updates into a separate session that uses statement logging.
Never turn off the binary log in production just to make the error stop. Skipping the binary log breaks point-in-time recovery and ruins every downstream replica you run. Always keep your logging rules intact while you update the table design or workflow.
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
What does the ER_BINLOG_ROW_INJECTION_AND_STMT_ENGINE symbol mean?
It means a transaction tried to write row events into a statement-only storage engine. MySQL blocks the query because it cannot write the change to the binary log.
Can I fix mysql error 1664 by turning off the binary log?
Turning off the log stops the error, but it breaks replication and backup recovery. Instead, move the table to an engine that supports row logging in production.
Does this error corrupt data on the primary database server?
No, the database engine stops the statement before it writes any bad data. It throws SQLSTATE HY000 to keep your primary server and replicas in sync.
Related guides
In this post