Create master slave replication GTID

# on node2 create file /root/.my.cnf
[client]
host=104.248.92.132
user=root
password=zabbix

# on node1 create new mysql user

CREATE USER 'repl'@'%' IDENTIFIED BY 'MaGiCdB1';

ALTER USER 'repl'@'%' IDENTIFIED WITH mysql_native_password BY 'MaGiCdB1';

GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';

FLUSH PRIVILEGES;
# this will show nothing
SELECT HOST,DB,USER FROM mysql.db;

# on node1 turn down all components which access database and set read only mode
FLUSH TABLES WITH READ LOCK;

# on node2 go to root user, create a backup
mysqldump --host=104.248.92.132 --user=root --password=zabbix --port=3306 --master-data=2 --all-databases > backup.sql

# if backup states error maybe it has the first line like:
# 'WARNING blah blah blah'
head -1 
# it must print:
# '-- MySQL dump 10.13  Distrib 8.0.27, for Linux (x86_64)'
# if it is not, then delete with: sed -i '1d' backup.sql

# on node2, test if user works fine
mysql -h'192.168.88.59' -P'3306' -u'root' -p'zabbix'

# on node1 execute:
show master status\G

# it will print:
#             File: master1.000041
#         Position: 31802172
#     Binlog_Do_DB: 
# Binlog_Ignore_DB: 
#Executed_Gtid_Set: ca9855c0-bbb6-11eb-819f-0242ac110002:1-197379

# on node2 execute:
stop slave;
reset slave;

# on node2 based on what was printed on node1 adjust the variables:
CHANGE MASTER TO
MASTER_HOST='104.248.92.132',
MASTER_USER='repl',
MASTER_PASSWORD='MaGiCdB1',
MASTER_LOG_FILE='master1.000041',
MASTER_LOG_POS=31802172;

# on node2
START SLAVE;

# on node1
CREATE DATABASE tempo;

# node2 check databases:
SHOW DATABASES;

# on node1 do:
DROP DATABASE tempo;

# on node1 do:
UNLOCK TABLES;

No comments: