一份MySQL5.6.x基于GTID主从复制配置实例,希望对你所有用,谢谢。
本文环境:
主库:CentOS6.7 x64 192.168.0.65 mysql-5.6.29
备库:CentOS6.7 x64 192.168.0.66 mysql-5.6.29
说明: 基于GTID的主从复制需要在配置文件中添加如下内容。
# vi /etc/my.cnf
[mysqld]
binlog-format = ROW
log-bin = master-bin
log-bin-index = master-bin.index
log-slave-updates = true
gtid-mode = on
enforce-gtid-consistency = true
master-info-repository = TABLE
relay-log-info-repository = TABLE
sync-master-info = 1
slave-parallel-workers = 2
binlog-checksum = CRC32
master-verify-checksum = 1
slave-sql-verify-checksum = 1
binlog-rows-query-log_events = 1
report-host = 192.168.1.120
server-id = 1
重启数据库:
# service mysqld restart
查看gtid信息:
mysql> show global variables like '%GTID%';
+---------------------------------+----------------------------------------+
| Variable_name | Value |
+---------------------------------+----------------------------------------+
| binlog_gtid_simple_recovery | OFF |
| enforce_gtid_consistency | ON |
| gtid_executed | |
| gtid_mode | ON |
| gtid_owned | |
| gtid_purged | |
| simplified_binlog_gtid_recovery | OFF |
+---------------------------------+----------------------------------------+
grant replication slave on *.* to 'repl'@'%' identified by '123456';
flush privileges;
说明: 默认只要server-id不相同即可。
# vi /etc/my.cnf
[mysqld]
binlog-format = ROW
log-bin = mysql-bin
relay-log = slave-relay-bin
relay-log-index = slave-relay-bin.index
log-slave-updates = true
gtid-mode = on
enforce-gtid-consistency = true
master-info-repository = TABLE
relay-log-info-repository = TABLE
sync-master-info = 1
slave-parallel-workers = 2
binlog-checksum = CRC32
master-verify-checksum = 1
slave-sql-verify-checksum = 1
binlog-rows-query-log_events = 1
report-host = 192.168.1.121
server-id = 11
重启数据库:
# service mysqld restart