RDS主庫、ECS自建mysql GTID 主從
現在公司的線上用的mysql數據庫,是購買的阿裏雲的RDS for mysql 服務,由於有服務需要讀取mysql的bin-log,並且基於RDS的只讀實例的bin-log不保證正確,所以自己搭建ECS從庫,註意從庫必須配置
binlog-format=ROW #為別的服務提供binlog
server_id=999 #避免server_id 跟master相同
gtid-mode=ON #開啟gtid模式
log-slave-updates #這裏作為中轉需要此參數,如需深入了解,情況官檔
enforce-gtid-consistency = ON #強制GTID的一致性
1、通過RDS數據備份,拉取全量備份
wget -c ‘<數據備份文件內網網下載地址>‘ -O full.tar.gz
2、用阿裏提供的解壓腳本(rds_backup_extract.sh)解壓下載好的文件 full.tar.gz
3、用 innobackupex --defaults-file=/etc/my.cnf --apply-log /data_of_mysql 恢復
4、指定datadir,重啟mysql,修改用戶密碼;
5、報這個錯時,Slave is not configured or failed to initialize properly. You must at least set --server-id to enable either a master or a slave. Additional error messages can be found in the MySQL error log.
use mysql
drop table slave_master_info;
drop table slave_relay_log_info;
drop table slave_worker_info;
drop table innodb_index_stats;
drop table innodb_table_stats;
6、根據 xtrabackup_slave_info中的第一行,設定 SET GLOBAL gtid_purged=‘‘
7、設定master信息,
change master to master_host=‘RDS_URL‘,
master_port=3306,
master_password=‘Passwd‘,
master_auto_position=1;
RDS主庫、ECS自建mysql GTID 主從