要求
星期5的10:30做的全备,11点发生的误操作,删除了student表里的所有数据,如何快速恢复数据到删除之前的状态?
恢复:
1.恢复10:30的全备
2.使用二进制日志恢复10点30到11点之间产生的数据
准备
做全备,使用mysqldump
mysqldump -uroot -p’Dooriya123#’ --databases yu_game>/yu_game_backup/yu_game.sql
确保二进制日志是否开启
root@yu_game 10:28 mysql>show variables like “log_bin”;
root@yu_game 10:58 mysql>flush logs; 生成一个全新的二进制日志文件,方便后面进行恢复
恢复(基于位置)
1.先进行全备进行恢复
[root@yu mysql]# cd /yu_game_backup/
[root@yu yu_game_backup]# ls
yu_game.sql
[root@yu yu_game_backup]# mysql -uroot -p'Dooriya123#' <yu_game.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
2.使用二进制日志恢复到drop table yu_game前的操作
主要是需要找到开始的位置和你需要恢复到的位置
[root@yu mysql]# mysqlbinlog -v yu-bin.000009 |grep -C 20 "drop database"
进行恢复,基于位置
[root@yu mysql]# mysqlbinlog --start-position=294 --stop-position=1291 yu-bin.000009 |mysql -uroot -p'Dooriya123#'
恢复(基于时间)
基于时间,进行恢复
1.先做全备
[root@yu mysql]# mysql -uroot -p'Dooriya123#' </yu_game_backup/yu_game.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
2.找到起始时间点和误操作之前的时间点
[root@yu mysql]# mysqlbinlog --start-datetime="2020-02-25 10:30:00" --stop-datetime="2020-02-25 11:00:00" Sanchuang-bin.000009 |mysql -uroot -p'Dooriya123#'