mysql全备并恢复数据

要求

星期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#'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值