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?
--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.
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.
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.
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With