Common SQL Errors

MySQL Error 1786 ER_GTID_UNSAFE_CREATE_SELECT - Fix and Prevent

Galaxy Team
August 7, 2025

<p>CREATE TABLE ... SELECT is not allowed with GTID_MODE=ON because it can break deterministic replication.</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 1786 ER_GTID_UNSAFE_CREATE_SELECT?

<p>MySQL Error 1786 ER_GTID_UNSAFE_CREATE_SELECT happens when you run CREATE TABLE ... SELECT while GTID mode is enabled. Split the operation into CREATE TABLE plus INSERT SELECT, or temporarily disable GTID mode to solve the problem.</p>

Error Highlights

Typical Error Message

Statement violates GTID consistency: CREATE TABLE ...

Error Type

GTID Consistency Error

Language

MySQL

Symbol

ER_GTID_UNSAFE_CREATE_SELECT

Error Code

1786

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 1786 ER_GTID_UNSAFE_CREATE_SELECT?

Error 1786 fires when a CREATE TABLE ... SELECT statement runs while GTID_MODE is ON. MySQL blocks the query because it cannot guarantee deterministic replication across servers.

GTID based replication requires every transaction to be uniquely identifiable and deterministic. A single statement that both creates a table and selects data can behave differently on source and replica, violating this guarantee.

Why should you fix it quickly?

Leaving the error unresolved halts the transaction, prevents table creation, and can break deployment scripts. In an automated pipeline this blockage cascades into application downtime or failed CI builds.

When does the error appear?

The error appears on MySQL 5.6.5 and later whenever GTID_MODE=ON and a CREATE TABLE ... SELECT is issued without the appropriate workarounds.

Common Causes

GTID mode enabled

GTID_MODE set to ON or ON_PERMISSIVE disallows non deterministic statements such as CREATE TABLE ... SELECT.

Mixed-format replication

Using mixed or statement based replication with GTIDs amplifies the non deterministic nature of the combined create-select syntax.

Legacy migration scripts

Older dump or migration tools often generate CREATE TABLE ... SELECT, unaware of modern GTID restrictions.

Related Errors

Error 1785 ER_GTID_UNSAFE_DELIMITER

Occurs when a delimiter command is unsafe under GTID mode.

Error 1782 ER_GTID_UNSAFE_NON_TRANSACTIONAL_TABLE

Triggered by updates to non transactional tables during GTID enforced sessions.

Error 1789 ER_GTID_UNSAFE_ALTER_DROP_TEMPORARY_TABLE

Altering or dropping a temporary table is blocked under GTID mode.

FAQs

Can I ignore error 1786?

No. Ignoring it leaves the table uncreated and the transaction uncommitted. Fix or disable GTIDs first.

Does MySQL 8 still block CREATE TABLE ... SELECT?

Yes. The rule applies to all versions that support GTIDs because the operation is nondeterministic.

Is binlog_format=ROW always safe?

Row based logging allows the statement but changes replication size and performance. Test before switching.

How does Galaxy help?

Galaxy flags unsafe statements in the editor and suggests deterministic rewrites, preventing the error 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