Common SQL Errors

MySQL Error 1592 ER_BINLOG_UNSAFE_STATEMENT - Full Fix Guide

Galaxy Team
August 7, 2025

<p>MySQL raises error 1592 when a potentially non-deterministic statement is written to the binary log while BINLOG_FORMAT is set to 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 1592 ER_BINLOG_UNSAFE_STATEMENT?

<p>MySQL Error 1592 ER_BINLOG_UNSAFE_STATEMENT appears when MySQL detects that a statement is unsafe to replicate with STATEMENT binlog format. Switch to ROW or MIXED format, or rewrite the query to be deterministic, to resolve the issue.</p>

Error Highlights

Typical Error Message

Unsafe statement written to the binary log using

Error Type

Replication and Binary Log Error

Language

MySQL

Symbol

ER_BINLOG_UNSAFE_STATEMENT

Error Code

1592

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1592 ER_BINLOG_UNSAFE_STATEMENT?

Error 1592 fires when the server tries to log a statement that may produce different results on replicas because BINLOG_FORMAT is STATEMENT. MySQL blocks the write to protect replication consistency.

The full message is: Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. %s. It highlights that your current query is considered unsafe for statement-based replication.

When does this error occur?

The error surfaces during data-changing commands such as UPDATE, INSERT, DELETE, or certain DDL operations executed while the binary log format is STATEMENT and the query contains non-deterministic factors like LIMIT without ORDER BY or non-transactional tables.

Why is it important to fix quickly?

If the statement were allowed, replicas could diverge from the primary server, breaking data integrity. Addressing the problem maintains replication correctness and avoids unexpected data drift.

What Causes This Error?

Non-deterministic queries, operations on tables without primary keys, or the use of specific functions cause MySQL to mark the statement as unsafe. The next section lists concrete causes.

How to Fix MySQL Error 1592

You can change the binlog format to ROW or MIXED, or rewrite the query to be deterministic. Each path is detailed with SQL examples below.

Common Scenarios and Solutions

Developers frequently hit the error during bulk updates with LIMIT or while altering MyISAM tables. Tightening ordering and adding primary keys remove the unsafe flag.

Best Practices to Avoid This Error

Set BINLOG_FORMAT=ROW in production, always include ORDER BY with LIMIT, prefer InnoDB with primary keys, and test write statements on a staging environment using Galaxy to catch warnings.

Related Errors and Solutions

Errors 1595 and 1665 also involve unsafe statements. They share fixes like switching binlog format or rewriting queries; details follow in the related errors section.

Common Causes

LIMIT without ORDER BY

Updating or deleting rows with LIMIT but no ORDER BY lets row selection vary between servers, making the statement unsafe.

Non-deterministic functions

Use of UUID(), NOW(), RAND(), or USER() inside data-changing statements yields different values on replicas.

Mixed transactional and non-transactional tables

Statements touching both InnoDB and MyISAM tables cannot be reproduced exactly with statement logging.

No primary key on target table

Without a primary key, MySQL cannot guarantee identical row order, flagging the statement as unsafe.

Related Errors

MySQL Error 1595 ER_BINLOG_UNSAFE_INSERT_IGNORE_SELECT

Raised when INSERT IGNORE SELECT is unsafe under statement logging. Fix by switching to ROW or rewriting the query.

MySQL Error 1665 ER_BINLOG_UNSAFE_AUTOINC_COLUMNS

Occurs when updating AUTO_INCREMENT columns under STATEMENT format. Use ROW format to resolve.

MySQL Error 1677 ER_BINLOG_ROW_MODE_AND_STMT_ENGINE

Triggered when statement-based logs hit non-transactional storage engines. Convert tables or switch formats.

FAQs

How do I know which part of my query is unsafe?

Enable session variable binlog_format warnings or run EXPLAIN to see if functions like RAND() or LIMIT without ORDER BY are present.

Can I set BINLOG_FORMAT per session?

Yes. Use SET SESSION BINLOG_FORMAT='ROW' before running the specific statement, then revert if necessary.

Does changing to ROW format hurt performance?

ROW logs more data, increasing disk usage, but replicas apply changes faster. On modern hardware, the trade-off is usually acceptable.

How does Galaxy help prevent this error?

Galaxy’s editor flags non-deterministic queries, suggests ROW format when needed, and lets teams share fixed queries, reducing the chance of unsafe statements reaching production.

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