Mysql 基於GTID主從複製

ChenAfrica發表於2020-12-25

環境

主(master):111.231.44.78
從(salve) :121.5.71.127

master 配置

# /etc/my.cnf
[mysqld]
server-id=78
log-bin=mysql-bin
log-slave-updates=true
skip_slave_start=1
gtid-mode=ON
enforce_gtid_consistency=on

salve 配置

# /etc/my.cnf
[mysqld]
server-id=127
relay_log=mysql-relay-bin
read_only=1
log-bin=mysql-bin
log_slave_updates=1
gtid-mode=ON
enforce_gtid_consistency=on

master節點建立授權使用者

# mysql5.7 版本
GRANT REPLICATION SLAVE ON *.* TO 'copyuser'@'121.5.71.127' IDENTIFIED BY  '密碼';
# mysql8.0 版本
create user 'copyuser'@'121.5.71.127' identified by '密碼';
grant all privileges on *.* to 'copyuser'@'121.5.71.127' with grant option;
# 重新整理
FLUSH PRIVILEGES;、
#  檢視主節點狀態
SHOW MASTER STATUS;

slave 節點建立連結

CHANGE MASTER TO
MASTER_HOST='111.231.44.78',
MASTER_USER='copyuser',
MASTER_PASSWORD='=密碼',
MASTER_PORT=3306,
MASTER_AUTO_POSITION = 1;

# 啟動從節點同步
start slave;
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章