MySQL | 腾讯云CDB本地同步库部署
需求
本文档是利用腾讯云主机自建本地MySQL实例作为CDB的同步库
步骤
CDB确认是否开启binlog
执行结果返回为ON
show global variables like 'log_bin';
本地实例过滤掉一些系统库
replicate-ignore-db = mysql
replicate-ignore-db = performance_schema
replicate-ignore-db = information_schema
gtid
确认下CDB
是否开启GTID
show global variables like 'gtid_mode';
若开启,则本地实例可以设置如下参数同步开启
gtid-mode = on
enforce-gtid-consistency = true
master-info-repository = TABLE
relay-log-info-repository = TABLE
sync-master-info = 1
slave-parallel-workers = 16
binlog-checksum = CRC32
master-verify-checksum = 1
slave-sql-verify-checksum = 1
binlog-rows-query-log_events = 1
权限添加
在CDB上添加同步和mysqldump的备份账号
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'腾讯云CVM IP地址'IDENTIFIED BY 'repl';
GRANT select,reload,PROCESS,lock tables,super ON *.* TO 'mysqlbackup'@'%' IDENTIFIED BY '备份密码';
flush privileges
全备份
把CDB上的库完整dump一份下来
mysqldump -h CDBip地址 -P 3306 -u mysqlbackup -p' 备份密码 ' --ignore-table=information_schema.* --ignore-table=performance_schema.* --ignore-table=mysql.* -R -E --single-transaction --master-data --databases DbNAME > all.sql
查看mysqldump的sql文件,确认备份截止的binlog位置和Pos位置
cat all.sql | grep 'CHANGE MASTER' | awk '{print $4,$5}'
设置同步
set global read_only=1;
CHANGE MASTER TO MASTER_HOST='CDBip地址',MASTER_USER='repl',MASTER_PASSWORD='repl',MASTER_PORT=3306,MASTER_LOG_FILE='备份截止binlog',MASTER_LOG_POS=备份截止Pos;
start slave;
查看同步状态
show slave status
数据测试
CDB主库尝试建立一个测试库,写入测试数据,本地从库正常同步,过程略。
Enjoy MySQL