假设我的master是172.16.15.8,要添加的slave是172.16.15.9
1:在主服务器执行备份操作(172.16.15.8)
/usr/bin/innobackupex --compress --no-timestamp --no-lock --flush-logs --socket=/var/lib/mysql/mysql.sock --user=root --password=********* `date -d "today" +"%Y%m%d"`
2:主服务器备份,从服务器拷贝解压
(1):压缩:tar cvf 20160822.tar /databak/data/20160822 (2):拷贝:scp -P 9422 root@172.16.15.8:/databak/data/20160822.tar /databak/data/20160822.tar 这步开始在slave执行 (3):解压:tar xvf 20160822.tar
3:开始还原拷贝的备份;
暂停副本的数据库服务,因为恢复的时候要求数据库是停止状态,而且要求数据的还原文件目录必须为空,不能有其他使用.
(1):解压:innobackupex --decompress /databak/data/databak/data/20160822/ (2):应用日志:innobackupex --apply-log --redo-only --compress --user=root --password=******* /databak/data/databak/data/20160822/ (3):恢复数据库innobackupex --copy-back /databak/data/databak/data/20160822/ (5)要注意,此时数据库还是暂停状态,重新修改my.cnf还要给一个权限
4:提起来数据库试试啊:service mysqld start
5:创建两端的复制账号:
创建复制账号:
create user 'repl'@'%' identified by 'repl4slave'; grant replication slave on *.* to 'repl'@'%' ; grant replication client to 'monitor'@'%' ; grant replication client,usage on *.* to 'monitor'@'%' ;
上面是老师讲的创建的账户的语句,我感觉没有下面我的好,仁者见仁智者见智,大家也可以指导一下.
也可以参考下面创建复制账号:
CREATE USER 'replication'@'172.16.15.9' IDENTIFIED BY '******'; update user set Repl_slave_priv='Y' where host='172.16.15.9'; update user set Repl_client_priv='Y' where host='172.16.15.9'; FLUSH PRIVILEGES;
6:找到日志的时间点,然后进行复制:
nl xtrabackup_binlog_info
这个点就是所谓的备份的日志点
7:做复制:
CHANGE MASTER TO MASTER_HOST='172.16.15.8',MASTER_PORT=3306,MASTER_USER='repl',MASTER_PASSWORD='Time.work.9818',MASTER_LOG_FILE='mysqlbinlog.000003',MASTER_LOG_POS=99721204;
打开复制:
START SLAVE;
参考文档:
STEP 5: Start the replication
Look at the content of the file xtrabackup_binlog_info, it will be something like:
Execute the CHANGE MASTER statement on a MySQL console and use the username and password you’ve set up in STEP 3:
TheSlave|mysql> CHANGE MASTER TO MASTER_HOST='$masterip', MASTER_USER='repl', MASTER_PASSWORD='$slavepass', MASTER_LOG_FILE='TheMaster-bin.000001', MASTER_LOG_POS=481;