5470

从阿里云RDS的mysql(master)同步到ECS中的mysql(slave)

乐果   发表于   2016 年 04 月 08 日 标签:mysql

1、下载二进制备份文件,解压:略

2、还原数据:

./innobackupex --defaults-file=/data/service/mysql/data/backup-my.cnf --apply-log /data/service/mysql/data

报错:

160408 13:49:57 innobackupex: Starting the apply-log operation

IMPORTANT: Please check that the apply-log run completes successfully.
           At the end of a successful apply-log run innobackupex
           prints "completed OK!".

./innobackupex version 2.3.4 based on MySQL server 5.6.24 Linux (x86_64) (revision id: e80c779)
xtrabackup: cd to /data/service/mysql/data
xtrabackup: This target seems to be not prepared yet.
xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(2113955558)
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup:   innodb_data_home_dir = ./
xtrabackup:   innodb_data_file_path = ibdata1:200M:autoextend
xtrabackup:   innodb_log_group_home_dir = ./
xtrabackup:   innodb_log_files_in_group = 1
xtrabackup:   innodb_log_file_size = 2097152
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup:   innodb_data_home_dir = ./
xtrabackup:   innodb_data_file_path = ibdata1:200M:autoextend
xtrabackup:   innodb_log_group_home_dir = ./
xtrabackup:   innodb_log_files_in_group = 1
xtrabackup:   innodb_log_file_size = 2097152
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: Using atomics to ref count buffer pool pages
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Memory barrier is not used
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, size = 100.0M
InnoDB: Completed initialization of buffer pool
InnoDB: Log file ./ib_logfile1 is of different size 50331648 bytes than other log files 2097152 bytes!
xtrabackup: innodb_init(): Error occured.

处理方法:

rm /data/service/mysql/data/ib_logfile1

3、编辑my.cnf:

[mysqld]
port = 3306
server_id = 2
datadir=/data/service/mysql/data

master-info-repository=file
relay-log-info_repository=file
binlog-format=ROW
gtid-mode=on
log-bin
log-slave-updates
enforce-gtid-consistency=true
innodb_checksum_algorithm=innodb
innodb_data_file_path=ibdata1:200M:autoextend
innodb_log_files_in_group=2
innodb_log_file_size=157286400

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

4、修改用户组:

chown -R mysql:mysql /data/service/mysql/data

5、启动mysql:

./bin/mysqld_safe --user=mysql &

6、登录mysql:./bin/mysql 执行:

use mysql;

truncate table  slave_relay_log_info;

truncate table  mysql.slave_master_info;

7、重新启程mysql

先停止:

./bin/mysqladmin shutdown;

再启动:

./bin/mysqld_safe --user=mysql &

8、查看slave:

more ./data/xtrabackup_slave_filename_info
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000967', MASTER_LOG_POS=47305

more ./data/xtrabackup_slave_info
SET GLOBAL gtid_purged='74b1f906-e4e8-11e4-9cdd-8038bc0baf6b:1-2438549, 7a48e4a6-e4e8-11e4-9cdd-8038bc0baf31:1-440317';
CHANGE MASTER TO MASTER_AUTO_POSITION=1

9、 登录mysql:./bin/mysql 配置slave:

use mysql;

SET GLOBAL gtid_purged='74b1f906-e4e8-11e4-9cdd-8038bc0baf6b:1-2438549, 7a48e4a6-e4e8-11e4-9cdd-8038bc0baf31:1-440317';

change master to master_host='******.mysql.rds.aliyuncs.com',master_port=3306,master_user='papa_root',master_password=‘***********',master_auto_position=1;

start slave;

show slave status;

乐果   发表于   2016 年 04 月 08 日 标签:mysql

0

文章评论