结合mysql replication那篇文章,只是把mydump备份使用了innobackupex工具替代,其他操作基本一样。使用innobackupex不需要手动锁表操作,锁表时间更短,备份更加快。
master:192.168.1.1 slave:192.168.1.2
master上进行备份操作
innobackupex --user=root --password=xxxxxx --host=127.0.0.1 --port=3306 --stream=tar
--defaults-file=/etc/my.cnf /tmp/| ssh [email protected] "mkdir /db; tar xfi - -C /db/"
innobackupex 以steam方式拷贝主服务器上的datadir目录中的数据到到从服务器/db。
slave停止mysql服务
/etc/init.d/mysqld stop
#rm /var/lib/mysql/* -rf #删除原始数据
#innobackupex --host=127.0.0.1 --user=root --password=xxxxx --port=3306 --apply-log /db/
#innobackupex --host=127.0.0.1 --user=root --password=xxxxx --port=3306 --copy-back /db/
cat /db/xtrabackup_binlog_info #查看二进制的日志和pos
mysql-bin.000011 1234
mysql>CHANGE MASTER TO
MASTER_HOST='192.168.1.2',MASTER_USER='repl',MASTER_PASSWORD='xxxxx',MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000011',MASTER_LOG_POS=1234;
mysql>start slave;
mysql>show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.2
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000011
Read_Master_Log_Pos: 1234
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 253
Relay_Master_Log_File: mysql-bin.000011
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1234
Relay_Log_Space: 409
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1923306
1 row in set (0.00 sec)
查看Slave_IO_Running,Slave_SQL_Running如果都是yes,则replication perfect!
本文出自 “小笔记” 博客,谢绝转载!