1. Set both the Master and Slave servers to read-only
mysql>SET @@global.read_only=ON;
service mysql stop
To enable GTIDs, you need to configure gtid-mode, log-bin, log-slave-updates, and enforce-gtid-consistency on both the master and slave servers (before MySQL 5.6.9, it was --disable-gtid-unsafe-statement ). In addition, the slave needs to add the skip-slave-start parameter in this link.
#vi /etc/my.cnf [mysqld] gtid-mode=on log-bin log-slave-updates enforce-gtid-consistency
mysql> change master to -> master_host='xxx.xxx.xxx.xxx', -> master_port=3306, -> master_user='xxx', -> master_password='xxx', -> master_auto_position=1; mysql > start slave;
At this point, the upgrade is completed. Now I will add a GTIDs Replication method for switching relay server or Master server.
GTIDs Replication can arbitrarily designate a server as the relay Slave server or Master server of another server.
For example, if there are three MySQL servers A, B, and C, A is the Master server of B and C. Currently, B is to be turned into a relay server for C. The specific operation method is as follows:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'lyz'@'C的ip地址' IDENTIFIED BY 'lyz';
(1) Stop the slave
mysql> stop slave;
(2)Configure slave
mysql> change master to -> master_host='B的ip地址', -> master_port=3306, -> master_user='lyz', -> master_password='lyz', -> master_auto_position=1;
(3)Start slave
mysql > start slave;
The above is the detailed content of MySQL - code example to upgrade BinLog Replication to GTIDs Replication in four steps. For more information, please follow other related articles on the PHP Chinese website!