How to Fix MySQL Error 1665 (ER_BINLOG_STMT_MODE_AND_ROW_ENGINE)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mysql error 1665 when a query touches a row-only table while statement logging runs. You fix this error by switching the binary log format to row mode or mixed mode. Database servers rely on the binary log to record changes for backups and replicas. When the log format conflicts with the table storage engine, the database blocks the query. Stopping the query prevents broken replicas and missing data across your cluster. Understanding why this happens helps your team keep production data

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 1665 when a query touches a row-only table while statement logging runs. You fix this error by switching the binary log format to row mode or mixed mode.

Database servers rely on the binary log to record changes for backups and replicas. When the log format conflicts with the table storage engine, the database blocks the query. Stopping the query prevents broken replicas and missing data across your cluster. Understanding why this happens helps your team keep production databases safe and running well.

Why mysql error 1665 happens in your database

The server raises this error under the symbol ER_BINLOG_STMT_MODE_AND_ROW_ENGINE and SQLSTATE code HY000. The official message says the server cannot run the statement or write to the log. This failure happens because the binary log format is set to statement mode. At the same time, at least one table in the query uses a row-only engine.

MySQL supports three main ways to write changes to the binary log. Statement mode writes the exact query text into the log file. Row mode records the actual data changes for each individual table row. Mixed mode uses statement logging by default but switches to row logging when needed.

Some storage engines only support row-level logging due to how they handle data. Distributed cluster engines and specialized storage layers often require row logging to keep data consistent. If your session uses statement mode and updates one of these tables, the engine halts. It cannot translate the row change into a safe statement log entry. The database stops the write right away to protect your downstream replicas from data drift.

How to diagnose and fix the failure in production

First, find out which query and table triggered the failure in your app logs. Check the storage engine for every table involved in that failed query. Next, inspect the current binary log format at both the global and session levels. Sometimes a specific app session changes its own log format before running a batch job.

To fix the problem, change the binary log format to row mode or mixed mode. Row mode is the safest choice for modern databases that use row-only storage engines. You can test the fix in a single session before making a global server change. Once the test succeeds, update the global server rule so new sessions use row mode.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Do not grant broad admin rights to app roles just to bypass logging rules. Letting an app change its own log format or skip logging breaks your audit trail. Skipping the binary log also leaves your read replicas out of sync with the primary. Instead, have a database admin apply the change through a controlled peer review process. During this review, make sure sensitive data like emails or card numbers remains masked.

How to prevent binary log format conflicts

Standardize your database settings across all test, staging, and production servers. When staging uses row mode and production uses statement mode, bugs slip into releases. Keep your server rules in version control so every team member sees the same settings. Review new table creations to see which storage engines your developers choose.

Also, check your client apps and migration tools for hidden session commands. Some older data tools force statement mode when they start a new database session. Updating these tools or removing those startup commands stops the error from coming back. Strong access controls also stop unapproved users from changing log settings on live servers.

Inspect every MySQL query and response in flight

Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.

First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.

Frequently asked questions

What does ER_BINLOG_STMT_MODE_AND_ROW_ENGINE mean?

This symbol means your session uses statement-based binary logging while querying a row-only storage engine. The database blocks the query because the engine can only log row changes.

Does changing the binary log format require a server restart?

No, an admin can update the binary log format dynamically on a running server. New client sessions will pick up the updated global format right away.

Is row mode or mixed mode better to fix mysql error 1665?

Row mode is usually better because it logs exact row changes for every query. Mixed mode also works, as it switches to row logging when touching row-only tables.

The query runs. The emails stay hidden.