Common SQL Errors

MySQL Error 1718: ER_BINLOG_UNSAFE_CREATE_REPLACE_SELECT - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>The statement-based binary log rejects CREATE ... REPLACE SELECT because row order is nondeterministic and can break replication consistency.</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 1718?

<p>MySQL Error 1718: ER_BINLOG_UNSAFE_CREATE_REPLACE_SELECT occurs when CREATE ... REPLACE SELECT is logged in STATEMENT mode. The nondeterministic row order can cause master and replica divergence. Switch to ROW binlog_format or rewrite the statement to remove REPLACE to resolve the issue.</p>

Error Highlights

Typical Error Message

CREATE... REPLACE SELECT is unsafe because the order in

Error Type

Replication Error

Language

MySQL

Symbol

ER_BINLOG_UNSAFE_CREATE_REPLACE_SELECT

Error Code

1718

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1718 (ER_BINLOG_UNSAFE_CREATE_REPLACE_SELECT)?

Error 1718 fires when MySQL tries to write a CREATE ... REPLACE SELECT statement to the binary log while binlog_format is STATEMENT or MIXED. The server marks the statement unsafe because REPLACE depends on row order, which may differ on replicas.

The error stops the statement to protect replication integrity. If the binary log is disabled or set to ROW, the same query runs without issue.

What Causes This Error?

Statement-based replication requires deterministic results. With CREATE ... REPLACE SELECT, the first matching row encountered is replaced, so varying SELECT order yields different outcomes. MySQL cannot guarantee identical order across nodes, so it blocks the operation.

The problem surfaces most often on production clusters that still use STATEMENT logging for performance or backward compatibility.

How to Fix MySQL Error 1718

The fastest remedy is to set binlog_format to ROW, either session-wide for the current connection or globally for the server. ROW logging records individual row changes and removes ordering ambiguity.

If changing the binary log format is impossible, rewrite the query: insert into a temporary table, index it, then apply REPLACE or INSERT ... ON DUPLICATE KEY UPDATE from that deterministic source.

Common Scenarios and Solutions

During zero-downtime migrations, teams often clone tables with CREATE OR REPLACE SELECT in STATEMENT mode and hit Error 1718. Switching to ROW for the migration window eliminates the block.

Scheduled ETL jobs running on replicas may break because master accepted the query in ROW but the job forces STATEMENT. Align formats across environments to prevent mismatches.

Best Practices to Avoid This Error

Use ROW binlog_format as a default in modern clusters. Where performance is critical, MIXED mode with key-based ORDER BY clauses can be acceptable, but test thoroughly.

Build idempotent loads with INSERT ... ON DUPLICATE KEY UPDATE instead of REPLACE to reduce nondeterminism. Always add explicit ORDER BY on primary keys when bulk loading.

Related Errors and Solutions

Errors 1592 (ER_BINLOG_UNSAFE_STATEMENT) and 1593 (ER_BINLOG_UNSAFE_AUTOINC_SELECT) also surface when nondeterministic statements are logged in STATEMENT mode. The fixes-switch to ROW or rewrite statements-mirror the solution for Error 1718.

Common Causes

Statement-based binary logging enabled

binlog_format=STATEMENT records SQL text, so MySQL rejects nondeterministic queries.

CREATE ... REPLACE SELECT without ORDER BY

Row replacement depends on retrieval order, which varies between master and replica.

MIXED logging with unsafe detection

In MIXED mode, MySQL falls back to STATEMENT when it believes a query is safe. Detection failure triggers Error 1718.

Related Errors

Error 1592: ER_BINLOG_UNSAFE_STATEMENT

General flag for unsafe statements in STATEMENT binlog mode.

Error 1593: ER_BINLOG_UNSAFE_AUTOINC_SELECT

Triggered when an INSERT SELECT with auto-increment columns is nondeterministic.

Error 1795: ER_BINLOG_UNSAFE_INSERT_SELECT_UPDATE

Raised for INSERT ... SELECT ... ON DUPLICATE KEY UPDATE when order is unpredictable.

FAQs

Can I ignore Error 1718 with sql_log_bin=0?

Disabling the binary log avoids the error but breaks replication and point-in-time recovery. Use only on standalone hosts.

Is MIXED logging safe enough?

MIXED mode works if MySQL switches to ROW for unsafe queries. Error 1718 proves the statement stayed in STATEMENT, so it is still unsafe.

Does adding ORDER BY fix the error?

ORDER BY can help but does not guarantee identical execution plans across nodes. The safest fix remains ROW logging.

How does Galaxy help prevent this error?

Galaxy surfaces replication-mode warnings in real time and suggests switching the session to ROW before execution, preventing runtime failures.

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