Common SQL Errors

MySQL Error 1661: ER_BINLOG_ROW_ENGINE_AND_STMT_ENGINE - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>MySQL error 1661 occurs when a single DML statement touches storage engines that need different binary logging formats, making it impossible to write the operation to the binary log.</p>

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error code 1661?

<p>MySQL Error 1661 (ER_BINLOG_ROW_ENGINE_AND_STMT_ENGINE) appears when one statement updates tables that require incompatible binlog formats. Split the statement or set binlog_format=ROW to resolve the issue.</p>

Error Highlights

Typical Error Message

Cannot execute statement: impossible to write to binary

Error Type

Binary Logging Error

Language

MySQL

Symbol

ER_BINLOG_ROW_ENGINE_AND_STMT_ENGINE

Error Code

1661

SQL State

HY000

Explanation

Table of Contents

What does MySQL Error 1661 (ER_BINLOG_ROW_ENGINE_AND_STMT_ENGINE) mean?

MySQL throws error 1661 with the message "Cannot execute statement: impossible to write to binary log" when a single statement involves both a row-incapable storage engine and a statement-incapable storage engine. The server cannot decide which binary logging format to use, so it blocks the statement to protect replication consistency.

The problem is most visible on replicated servers that rely on the binary log. Production workloads suddenly halt, making a fast fix critical to avoid data drift between the primary and replicas.

What Causes This Error?

The error is triggered when a DML statement (INSERT, UPDATE, DELETE, REPLACE) touches at least two tables that have conflicting logging requirements. Engines like NDBCluster need ROW logging, while engines such as MEMORY reject ROW and accept only STATEMENT.

A mixed binlog_format (MIXED) cannot solve this conflict because both engines refuse one of the two formats. MySQL therefore aborts execution before any data is changed.

How to Fix MySQL Error 1661

Split the operation into two statements, each affecting only one engine type. This lets the server pick the correct logging format for every statement.

If possible, migrate all affected tables to an engine that supports row-based logging and set binlog_format=ROW. Row logging works for every engine that participates in replication, eliminating future conflicts.

Common Scenarios and Solutions

INSERT INTO persistent_table SELECT ... FROM temp_memory_table is a classic failure pattern. Rewrite the workflow to insert into a temporary InnoDB table first, or use two statements.

Bulk UPDATE joining an NDB table with an InnoDB table also fails. Perform the UPDATE on the NDB table using a staging table or process the join in application code.

Best Practices to Avoid This Error

Standardize on one storage engine for write-intensive workloads. Use InnoDB for transactional data to avoid cross-engine statements.

Configure all servers in a replication group with binlog_format=ROW. Test schema changes in staging to catch cross-engine statements early.

Related Errors and Solutions

MySQL Error 1580 (BINLOG_FORMAT_MIXED_ENGINE) fires when a statement refers to a table that requires a specific format while binlog_format=MIXED. The fix is similar: switch to ROW or alter the table engine.

Common Causes

Mixed storage engines in one statement

A query updates or inserts into tables that belong to different engines with incompatible logging rules, such as MEMORY and NDB.

JOIN between incompatible engines

Statements joining an NDBCluster table and a MEMORY table force MySQL to decide on a single format and trigger the error.

Triggers or cascades touching other engines

After triggers fire and manipulate tables in another engine, the composite event becomes unloggable.

MIXED binlog_format on replication

Even with binlog_format=MIXED, MySQL cannot auto-switch when both formats are invalid for the engines involved.

Related Errors

MySQL Error 1580: BINLOG_FORMAT_MIXED_ENGINE

Occurs when a single table requires a specific logging format that conflicts with the current binlog_format setting.

MySQL Error 1592: BINLOG_FORMAT_CHANGED

Raised when the server cannot safely switch binlog_format during execution.

MySQL Error 1598: MASTER_FATAL_ERROR_READING_BINLOG

Replication fails because the slave cannot interpret events written with an unsupported format.

FAQs

Why does setting binlog_format=MIXED not fix error 1661?

MIXED still logs some statements in STATEMENT format. If any involved engine refuses STATEMENT logging, the conflict remains.

Can I ignore the error on a non-replicated server?

Yes, disabling binary logging removes the conflict, but you lose point-in-time recovery and replication capabilities.

Does switching to ROW logging slow performance?

ROW logging generates larger binlogs but is faster to apply on replicas. Compression and binlog rotation mitigate storage impact.

How does Galaxy help avoid this error?

Galaxy’s SQL editor warns when a query mixes incompatible engines, and its AI copilot suggests engine-aligned rewrites before execution.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo