Common SQL Errors

MySQL Error 1666: ER_BINLOG_ROW_INJECTION_AND_STMT_MODE - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>The server refuses to execute a statement because it would inject row-based events while BINLOG_FORMAT is STATEMENT.</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 1666?

<p>MySQL Error 1666: ER_BINLOG_ROW_INJECTION_AND_STMT_MODE occurs when a statement needs row-based logging but the server is set to STATEMENT mode. Switch BINLOG_FORMAT to ROW or MIXED, or disable the offending feature, to execute successfully.</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_INJECTION_AND_STMT_MODE

Error Code

1666

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 1666?

Error 1666 signals that MySQL cannot record the current statement in the binary log. The operation generates row-based events, yet the server or session is configured for statement-based logging.

The error text is: Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.

When does it occur?

The error appears in MySQL 5.6 and later when triggers, foreign key cascades, or Group Replication inject row events while the binlog format is locked to STATEMENT.

It also shows up during online DDL, INSERT ... ON DUPLICATE KEY UPDATE, or other operations that MySQL logs internally as row events.

Why is it important to fix?

If the server cannot write to the binary log, replication stops and point-in-time recovery becomes impossible. Production environments relying on replicas or backups face data-loss risk until logging is restored.

What Causes This Error?

The main cause is a mismatch between required row-based logging and an enforced STATEMENT binlog format. MySQL blocks the query to protect replication consistency.

Session-level overrides, restrictive startup options, or unexpected internal row injections can trigger the mismatch.

How to Fix MySQL Error 1666

The quickest fix is to switch the binary log format to ROW or MIXED for the session or globally, then re-run the statement.

Alternatively, disable the feature producing row events, such as a trigger, before executing the statement, then re-enable it.

Common Scenarios and Solutions

During Group Replication, use mixed or row format so member nodes can replay row events reliably.

For online ALTER TABLE, set binlog_format='ROW' in the same session to let metadata changes log safely.

Best Practices to Avoid This Error

Standardize on MIXED or ROW binlog format in production to avoid format conflicts.

Automate environment checks that alert when binlog_format differs from the application requirement.

Related Errors and Solutions

Errors 1592, 1665, and 1670 also involve binary log issues. They usually resolve after switching to ROW format or disabling unsafe statements.

Common Causes

Trigger or Foreign Key Cascades

Triggers and cascades generate row images internally, forcing row-based logging that conflicts with STATEMENT mode.

Group Replication Row Events

Group Replication injects row events for conflict detection. STATEMENT mode blocks these writes, leading to error 1666.

Online DDL or Partition Operations

DDL features that modify data online emit row events, which cannot be logged in STATEMENT format.

Session Override of binlog_format

A client may enforce STATEMENT at session level while the workload expects ROW, causing a mismatch.

Related Errors

Error 1592 - binlog_format_row_insufficient_priv

Occurs when a user lacks the SUPER privilege required for row format changes. Grant or change user permissions.

Error 1665 - ER_BINLOG_ROW_MODE_AND_STMT_ENGINE

Raised when a storage engine needs row format but logging is STATEMENT. The fix is identical: switch to ROW.

Error 1670 - ER_BINLOG_ROW_INJECTION_AND_STMT_ENGINE

Triggers when row injection collides with STATEMENT mode at engine level. Resolved by using ROW or MIXED format.

FAQs

Can I ignore error 1666 if I do not use replication?

No. The server still relies on the binary log for point-in-time recovery and some online DDL features. Ignoring the error risks data loss.

Does changing binlog_format affect performance?

ROW logging writes more data to the binlog but usually has minimal runtime impact. Compression and faster storage reduce overhead.

Will MIXED format always prevent error 1666?

In most cases yes. MySQL selects ROW for unsafe statements and STATEMENT for others, reducing conflicts.

How does Galaxy help?

Galaxy surfaces server variables in the editor sidebar. You can set binlog_format per tab and share the validated query with teammates to avoid future errors.

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