注意:你的備份的時間應該在你的binlog保存時間范圍內(nèi)
環(huán)境:
主庫: 阿里云RDS Mysql 5.6
從庫: ECS機器上自建從庫 Centos 7.4
- setp 1 在阿里云RDS后臺建立只讀權(quán)限賬號
- setp 2 使用RDS自帶的備份功能,進行物理備份,并恢復到ECS機器
參考鏈接:
備份: https://help.aliyun.com/document_detail/26206.html
恢復: https://help.aliyun.com/knowledge_detail/41817.html
- setp 3 修改/etc/my.cnf
[mysqld]
datadir=/opt/mysql-data ## 指定數(shù)據(jù)文件莲蜘,根據(jù)setp 2的恢復操作
basedir=/opt/mysql
innodb_checksum_algorithm=innodb
innodb_data_file_path=ibdata1:200M:autoextend
innodb_log_files_in_group=2
innodb_log_file_size=572864000
innodb_undo_directory=.
innodb_undo_tablespaces=0
server-id = 723456789 ## 這里只需要跟主庫不一樣就行了
log_bin = /opt/mysql-binlog/mysql-bin.log
expire_logs_days = 7
max_binlog_size = 100M
replicate-do-db = test ## 此處為需要同步的庫
replicate-ignore-db = mysql ## 此處為不需要同步的庫
gtid_mode=on
enforce_gtid_consistency=on
binlog_format=row ## 阿里云RDS開啟ROW(默認就是)
relay_log=/opt/mysql-relay-data/relay.log
log-slave-updates=1
- setp 4 啟動mysql
可能會遇到的問題:
[ERROR] Error creating master info: Error removing old repository.
[ERROR] Failed to create or recover replication info repository.
解決:
use mysql
drop table mysql.innodb_index_stats;
drop table mysql.innodb_table_stats;
drop table mysql.slave_master_info;
drop table mysql.slave_relay_log_info;
drop table mysql.slave_worker_info;
source /opt/mysql/share/mysql_system_tables.sql
- setp 5 查看備份的gtid
在具體的數(shù)據(jù)目錄(就是你恢復備份的文件夾)
/opt/mysql-data/xtrabackup_info
找到以下這行票渠,取最后一條 c619dfe7-04aa-11e8-dbf4-6c92bf3fe77d:1-325898712,
e3f32949-04ac-11s8-bbw5-0425c5dcs34b:1-207283
binlog_pos = filename 'mysql-bin.001477', position 87871098, GTID of the last change 'c619dfe7-04aa-11e8-dbf4-6c92bf3fe77d:1-325898712,
e3f32949-04ac-11s8-bbw5-0425c5dcs34b:1-207283'
- setp 6 配置從庫
進入mysql
reset slave;
reset master;
change master to master_auto_position=1;
SET @@GLOBAL.GTID_PURGED='c619dfe7-04aa-11e8-dbf4-6c92bf3fe77d:1-325898712,
e3f32949-04ac-11s8-bbw5-0425c5dcs34b:1-207283';
change master to master_host = 'RDS地址' ,master_port = 3306, master_user = 'RDS用戶',master_password='RDS密碼';
啟動slave
start slave;