Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL GTID consistency violation

Tags:

I am trying to create a table from a select statement, and it give me a GTID consistency violation. [HY000][1786] Statement violates GTID consistency: CREATE TABLE ... SELECT.

create TABLE tags_mentions as     select t.*, st.ts, m.user_id_from, m.user_id_to from Tags as t join Mentions as m         on t.status_id = m.status_id AND m.user_id_from != m.user_id_to         left join Statuses as st on t.status_id = st.status_id; 

What is GTID consistency, and how can I fix the SQL statement to avoid the violation?

like image 510
Jiho Noh Avatar asked Nov 21 '16 15:11

Jiho Noh


People also ask

What is Gtid consistency?

--enforce-gtid-consistency only takes effect if binary logging takes place for a statement. If binary logging is disabled on the server, or if statements are not written to the binary log because they are removed by a filter, GTID consistency is not checked or enforced for the statements that are not logged.

What is Gtid mode in MySQL?

A global transaction identifier (GTID) is a unique identifier created and associated with each transaction committed on the server of origin (source). This identifier is unique not only to the server on which it originated, but is unique across all servers in a given replication setup.

What is set Gtid purged?

The set-gtid-purged function is set to AUTO by default in the GUI and it seems everytime you want to export without this parameter - you have to change it to OFF in Data Exports - Advanced options. To make it worse - the setting is not remembered.


2 Answers

If you want to fix the error another way, you can concisely create the table and insert separately with:

CREATE TABLE new_table LIKE old_table;  INSERT new_table SELECT * FROM old_table; 
like image 136
David Thomas Avatar answered Oct 06 '22 19:10

David Thomas


CREATE TABLE ... SELECT is not safe for statement-based replication. When using row-based replication, this statement is actually logged as two separate events — one for the creation of the table, and another for the insertion of rows from the source table into the new table just created.

When this statement is executed within a transaction, it is possible in some cases for these two events to receive the same transaction identifier, which means that the transaction containing the inserts is skipped by the slave. Therefore, CREATE TABLE ... SELECT is not supported when using GTID-based replication.

like image 22
DarbyM Avatar answered Oct 06 '22 19:10

DarbyM