适合mysql版本:4.1~5.7
所有数据库机器损坏,只有全备和binlog情况下恢复数据库到某个时间点
方法1:全备+binlog server
准备两台机器:binlog server机器,恢复机器
1、构造binlog server
把所有的binlog文件拷贝到一台机器,这个机器叫master binlog server
这个机器安装好mysql空实例,然后设置好Server-id ,auto.cnf(server-uuid)
master binlog server:
Server-id 从binlog文件里获取
mysql-bin.xxxx
mysql-bin.index 根据目前有多少个binlog文件构造出mysql-bin.index
server-uuid 从binlog文件里获取
2、
恢复机器上需要把全备恢复出来
mysqldump --single-stranaction --master-data=2
3、
根据binlog点把恢复出来的数据change 到master binlog server上
4、
start slave UNTIL master_log_file=‘binlog.000002‘,master_log_pos=829090187
MySQL启动异步复制SLAVE端的UNTIL语法
START SLAVE UNTIL master_log_file=‘binlog.000002‘,master_log_pos=829090187
START SLAVE [thread_type [, thread_type] ... ]
START SLAVE [SQL_THREAD] UNTIL
MASTER_LOG_FILE = ‘log_name‘, MASTER_LOG_POS = log_pos
START SLAVE [SQL_THREAD] UNTIL
RELAY_LOG_FILE = ‘log_name‘, RELAY_LOG_POS = log_pos
UNTIL语法不可以用在IO_THREAD上
方法2:重做relay-log
1. 把主库上的binlog cp到目标库上,改成relay-log的名字
2. 利用change master to语句,让恢复的库知道自已是一个从库
官方文档
The next example shows an operation that is less frequently employed.
It is used when the slave has relay log files that you want it to
execute again for some reason. To do this, the master need not be
reachable. You need only use CHANGE MASTER TO and start the SQL thread
(START SLAVE SQL_THREAD):
CHANGE MASTER TO
RELAY_LOG_FILE=‘slave-relay-bin.006‘,
RELAY_LOG_POS=4025;
1. 全备恢复,得到要change的binlog点位置
file:mysql-bin.006
pos:4025
2. 把主库上的binlog cp到恢复到目标库上,改成relay-log的名字
ls mysql-bin.0*|awk -F. ‘{print "cp "$0" relay-bin."$2}‘|sh
3. 利用change master to语句,让恢复的库知道自已是一个从库
change master to master_host=‘xxx‘; xxx随便一个ip都行,即使不存在的ip也行,这句主要是让mysql知道自己是一个从库
执行之后会自动生成
relay-log.info
relay-bin.index
4. 如果第二步出错,把 relay-log.info和relay-bin.index 删掉一次 ,再执行多次change master to
5. 构造relay-bin.index
ls relay-bin.0*|awk ‘{print "./"$0}‘>relay-bin.index
6. 滚动relay-log
flush logs;
7. CHANGE MASTER TO
RELAY_LOG_FILE=‘relay-bin.006‘,
RELAY_LOG_POS=4025;
8. start slave sql_thread;
9. show slave status;