简体   繁体   English

MySQL GTID 一致性违规

[英]MySQL GTID consistency violation

I am trying to create a table from a select statement, and it give me a GTID consistency violation.我试图从 select 语句创建一个表,它给了我一个 GTID 一致性违规。 [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?什么是 GTID 一致性,如何修复 SQL 语句以避免违规?

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. CREATE TABLE ... SELECT对于基于语句的复制是不安全的。 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.因此,使用基于 GTID 的复制时不支持CREATE TABLE ... SELECT

From here https://dev.mysql.com/doc/refman/5.6/en/replication-options-gtids.html从这里https://dev.mysql.com/doc/refman/5.6/en/replication-options-gtids.html

Since only transactionally safe statements can be logged when --enforce-gtid-consistency is enabled, it follows that the operations listed here cannot be used with this option:由于在启用--enforce-gtid-consistency--enforce-gtid-consistency记录事务安全语句,因此此处列出的操作不能与此选项一起使用:

  • CREATE TABLE ... SELECT statements CREATE TABLE ... SELECT语句
  • CREATE TEMPORARY TABLE statements inside transactions在事务中CREATE TEMPORARY TABLE语句
  • Transactions or statements that update both transactional and non-transactional tables同时更新事务表和非事务表的事务或语句

You seem to have enforce GTID set.您似乎已强制设置 GTID。 So this statement is not allowed.所以这个说法是不允许的。

If you do not care to replicate it on the slave, you can turn off the binlog:如果你不想在slave上复制它,你可以关闭binlog:

set sql_log_bin=0;
create table ... select ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM