MySQL錯誤ERROR 1786 (HY000)解決

務上須要支持create table XXX as select * from XXX; 這種建立表的語法,可是MySQL5.7.x版本里面gtid是開啓的,會報錯html

ERROR 1786 (HY000):Statement violates GTID consistency: CREATE TABLE ... SELECT.

官方說明:https://dev.mysql.com/doc/refman/5.7/en/replication-gtids-restrictions.htmlmysql

CREATE TABLE ... SELECT statements.  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.

解決辦法關閉GTID模式:
my.cnf裏面修改參數爲:sql

gtid_mode = OFF
enforce_gtid_consistency = OFF

重啓MySQL,再次建立成功:ide

mysql> show variables like '%gtid_mode%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | gtid_mode | OFF | +---------------+-------+ 1 row in set (0.01 sec) mysql> show variables like '%enforce_gtid_consistency%'; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | enforce_gtid_consistency | OFF | +--------------------------+-------+ 1 row in set (0.01 sec) mysql> create table t1 as select * from BS_CONT; Query OK, 0 rows affected (0.12 sec)
相關文章
相關標籤/搜索