1. 主库热备数据
1. mkdir -p /data/backup
2. xtrabackup --defaults-file=/etc/my.cnf --socket=/tmp/mysql.sock --user=root --password=123 --backup --target-dir=/data/backup/full
3. scp -rp /data/backup/* 172.16.1.53:/data/backup/
2. 从库备份主库数据
从:
mv /data/3306/data/* /tmp/ 清空数据
mv /data/3306/binglog/ /tmp/ 清空binglog日志
xtrabackup --prepare --target-dir=/data/backup/full
xtrabackup --copy-back --target-dir=/data/backup/full
[root@db01 data]# chown -R mysql.mysql /data/*
[root@db01 data]# /etc/init.d/mysqld start
3. 构建主从关系
1. 主库 获得binglog,位置点信息,构建主从语句:
mysql > show master status;
mysql > help change master to;
2. 从库构建主从复制:
mysql> reset slave;
Query OK, 0 rows affected (0.01 sec)
mysql> CHANGE MASTER TO
MASTER_HOST='10.0.0.51',
MASTER_USER='repl',
MASTER_PASSWORD='123',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000002',
MASTER_LOG_POS=156,
MASTER_CONNECT_RETRY=10;
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
3. 查看主从复制:
mysql> show slave statusG