1 找到从数据库断了的时间,以及binlog 文件名
2 到主服务器找到对应的binlog 文件 用mysqlbinlog 命令去查询该时间点的pos
mysqlbinlog --start-datetime="2014-03-04 17:35:01 --stop-datetime="2014-03-04 17:37:01" /var/log/mysql/binlog.000006 > log3.txt
3 在从服务器上停掉mysql slave
4 在从服务器上执行
CHANGE MASTER TO MASTER_HOST='192.168.1.8',MASTER_USER='rsync',MASTER_PASSWORD='123456',MASTER_PORT=3306,MASTER_LOG_FILE='binlog.000006',MASTER_LOG_POS=272267720;
5 在从服务器上执行 slave start 开起从服务
6 在从服务器上执行 show slave status\G; 看到是同步OK 的这个时候你可以看日志会从断点的时候开始更新,你可以看日志。
7 完成
这里我给个监控mysql主从的脚本
vi check-master-slave.sh
#!/bin/bash
# To determine whether slave is running or not.
#!/bin/bash
#Author: lrm
#Date: 2012-06-24
YYYY=`date "+%Y"`
MM=`date "+%m"`
DD=`date "+%d"`
HH=`date "+%H"`
mm=`date "+%M"`
ss=`date "+%S"`
date="$YYYY-$MM-$DD-$HH:$mm:$ss"
############################################################################
mysql_path=/usr/bin/mysql
user="root"
password="123456"
ip=$(/sbin/ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk '{print $2;}' | awk -F':' '{print $2;}' | head -1)
Slave_IO_Running=$($mysql_path -u$user -p$password -e 'show slave status\G' | grep "Slave_IO_Running" | awk '{print $2}')
Slave_SQL_Running=$($mysql_path -u$user -p$password -e 'show slave status\G' | grep "Slave_SQL_Running" | awk '{print $2}')
if [ "$Slave_IO_Running" = "Yes" -a "$Slave_SQL_Running" = "Yes" ]
then
echo $date -- "Slave is running!"
else
echo $date -- "Slave is not running!"
echo "gatewang_db-mster-to-slave error" | mail -s "mysql_db-mster-to-slave is error" [email protected]
echo $date -- "Slave is not running!" >> /var/log/mysql/mysql_slave.error.log
fi
添加自动任务 每分钟去执行就好了,这里也会写日志方便断点找还原点时间的POS