Common SQL Errors

MySQL Error 1665: ER_BINLOG_STMT_MODE_AND_ROW_ENGINE - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>The server refuses to execute a statement because BINLOG_FORMAT=STATEMENT while at least one referenced table requires row-based logging, blocking binary log writes.</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 1665 ER_BINLOG_STMT_MODE_AND_ROW_ENGINE?

<p>MySQL Error 1665 ER_BINLOG_STMT_MODE_AND_ROW_ENGINE occurs when you run a statement under BINLOG_FORMAT=STATEMENT against a table that can only be logged in ROW mode. Switch to MIXED or ROW binlog format, or change the table’s storage engine to resolve the issue.</p>

Error Highlights

Typical Error Message

Cannot execute statement: impossible to write to binary

Error Type

Replication / Binary Log Error

Language

MySQL

Symbol

ER_BINLOG_STMT_MODE_AND_ROW_ENGINE

Error Code

1665

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1665 ER_BINLOG_STMT_MODE_AND_ROW_ENGINE?

The error message “Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging” means MySQL cannot safely record the statement in the binary log.

Binary logging guarantees replication integrity. When BINLOG_FORMAT is STATEMENT, MySQL logs the SQL text. Some storage engines, temporary tables, or special columns only support row-based logging. When such a table is touched while STATEMENT mode is active, the server stops and raises error 1665.

What causes this error?

The primary trigger is running with global or session BINLOG_FORMAT=STATEMENT while referencing a table that is flagged for row-based logging only, such as NDB, MEMORY with certain features, or a table containing TIMESTAMP columns with DEFAULT CURRENT_TIMESTAMP in older versions.

User-level SET commands, replication filters, or application frameworks that force STATEMENT logging can surface the error during normal DML operations.

How to fix MySQL Error 1665

Switch the logging format to MIXED or ROW before executing the statement. This lets MySQL decide per statement or forces row images, satisfying the engine requirement.

Alternatively, migrate the problematic table to a STATEMENT-compatible engine like InnoDB. In edge cases, you can temporarily disable binary logging in the session if replication consistency is not needed.

Common scenarios and solutions

Bulk inserts into an NDB table fail on STATEMENT format. Solution: SET SESSION binlog_format='ROW' before the transaction.

A migration script sets STATEMENT mode for speed but also touches a MEMORY table with auto-updated timestamps. Switch to MIXED, or split the script into two transactions with different formats.

Best practices to avoid this error

Keep servers on MIXED binlog format by default. It provides STATEMENT advantages while automatically falling back to ROW when required.

Standardize on InnoDB for transactional tables unless a specific engine is mandatory. Document any row-only engines so developers know to adjust binlog settings.

Related errors and solutions

Error 1660 (ER_BINLOG_ROW_ENGINE_AND_STMT_ENGINE): Opposite mismatch when BINLOG_FORMAT=ROW and a statement-only engine is used. Fix by switching to STATEMENT or MIXED.

Error 1792 (ER_BINLOG_FORMAT_TOO_SMALL): Server refuses ROW-based event because slave version is too old. Upgrade replicas or set binlog_row_format=MINIMAL.

Common Causes

Row-only storage engine used

Engines like NDB Cluster, ARCHIVE, or certain MEMORY configurations can be logged only in ROW mode, triggering the mismatch.

Forced STATEMENT logging in code

Applications that issue SET SESSION binlog_format='STATEMENT' for performance forget to reset it, leading to replication failures.

Legacy tables with special columns

Tables containing unsafe constructs for STATEMENT logging, such as non-deterministic functions or ON UPDATE CURRENT_TIMESTAMP in old MySQL versions, can cause the error.

Related Errors

ER_BINLOG_ROW_ENGINE_AND_STMT_ENGINE (1660)

Raised when BINLOG_FORMAT=ROW but a statement-only engine is used. Switch formats or engines.

ER_BINLOG_FORMAT_TOO_SMALL (1792)

Occurs when row events cannot be applied on older replica versions. Upgrade or adjust row format settings.

FAQs

Can I ignore MySQL error 1665?

No. Ignoring it breaks replication consistency because the statement will not be logged. Fix the binlog format mismatch instead.

Is MIXED binlog format safe?

Yes. MySQL automatically chooses STATEMENT when deterministic and ROW when required, preventing error 1665 while minimizing log size.

Which engines require row-based logging?

NDB, ARCHIVE, BLACKHOLE, and some MEMORY tables. Additionally, tables using spatial data or non-deterministic defaults may need ROW.

How does Galaxy help?

Galaxy surfaces session variables inside the query editor and warns when binlog_format conflicts with engine settings, letting you switch modes before running the statement.

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