码迷,mamicode.com
首页 > 数据库 > 详细

MYSQL主从配置之innobackupex

时间:2016-05-31 10:36:18      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

1, 主库:备份数据库到从库

1),备份脚本
mycnf=/etc/my.cnf
user=root
passwd=xxxxxxxxxxxxxxxxx
socket=/data/mysql/3306/var/run/mysql.sock

dest_ip=192.168.30.27
dest_user=root
dest_dir=/data/mysql_19
backupname=mysql_`date +%F_%H-%M-%S`.tar.gz
innobackupex  --user=$user --password=$passwd --defaults-file=$mycnf --no-lock  --socket=$socket --stream=tar $dest_dir |ssh $dest_user@$dest_ip "gzip > $dest_dir/$backupname"

2),主库上配置同步账号

grant select on mysql.* to zabbix@localhost identified by 123456

2,从库:

1)停止从库mysql ,并删除数据

/etc/init.d/mysqld stop
rm -rf /opt/mysql/3306/data/*

2),解压到从库的数据目录:,参数i为忽略zero

tar xvfi backup.tar -C /opt/mysql/3306/data

 

3)还原到从库的数据目录   --apply-log

# innobackupex --user=root --socket=/opt/data/mysql/3306/var/run/mysql.sock --defaults-file=/opt/data/mysql/3306/var/my.cnf  --apply-log /opt/data/mysql/3306/data
innobackupex --user=root --apply-log /opt/data/mysql/3306/data
chown -R mysql:mysql /opt/data/mysql      权限配置

 

4)查看备份的 position 

cat xtrabackup_binlog_info
mysql-bin.003786        275137157

 

5)启动从库 mysql

nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/opt/data/mysql/3306/var/my.cnf 2>&1 &

 

6)配置从库

/usr/local/mysql/bin/mysql  --socket=/opt/data/mysql/3306/var/run/mysql.sock -uroot -p
change master to
MASTER_HOST=192.168.30.19,
MASTER_USER=slaves,
MASTER_PASSWORD=JQFvS4EPazp,
MASTER_PORT=3306,
MASTER_LOG_FILE=mysql-bin.003786,
MASTER_LOG_POS=275137157;

start slave; show slave status\G

 

 7)修复报错  ./mysql/proc‘ is marked as crashed and should be repaired 

mysqlcheck --repair mysql proc --socket=/opt/data/mysql/3306/var/run/mysql.sock -uroot -p
stop slave;
start slave;

 

 
 

MYSQL主从配置之innobackupex

标签:

原文地址:http://www.cnblogs.com/tankt101/p/5544843.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!