## GTID: Global Transaction ID gtid_mode = on # 使用主从复制的时候必须启用 enforce_gtid_consistency= on # 使用主从复制的时候必须启用 log-slave-updates = 1 # For all slave servers skip_slave_start = 1
Warning When using statement-based logging for replication, it is possible for the data on the master and slave to become different if a statement is designed in such a way that the data modification is nondeterministic; that is, it is left to the will of the query optimizer. In general, this is not a good practice even outside of replication. For a detailed explanation of this issue, see Section B.5.7, “Known Issues in MySQL”.
重新启动MySQL服务器,可以查看GTID是否正常启动:
1 2 3 4 5 6 7 8 9 10 11 12 13
mysql> show global variables like '%gtid%'; +---------------------------------+-----------------------------------------------+ | Variable_name | Value | +---------------------------------+-----------------------------------------------+ | binlog_gtid_simple_recovery | OFF | | enforce_gtid_consistency | ON | | gtid_executed | 3591a291-699c-11e6-8386-0242ac1100f2:1-1830 | | gtid_mode | ON | | gtid_owned | 3591a291-699c-11e6-8386-0242ac1100f2:1831#127 | | gtid_purged || | simplified_binlog_gtid_recovery | OFF | +---------------------------------+-----------------------------------------------+ 7 rows in set (0.02 sec)
执行一条更新语句,然后就可以看到GTID的状态了:
1 2 3 4 5 6 7 8 9 10 11
mysql> show master status\G; *************************** 1. row *************************** File: mysql-bin.000001 Position: 1070635555 Binlog_Do_DB: Binlog_Ignore_DB: mysql,information_schema,performance_schema Executed_Gtid_Set: 3591a291-699c-11e6-8386-0242ac1100f2:1-1745 1 row in set (0.00 sec)
ERROR: No query specified
启动主从复制
创建Master的Replica帐号:
1 2
CREATEUSER'repl'@'%' IDENTIFIED BY'slave'; GRANT REPLICATION SLAVE ON*.*TO'repl'@'%';
fify@server-base:/tmp/irenshi⟫ mysql -uroot -proot -h192.168.1.4 -P3307 < irenshi.sql ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty.