[英]How do I restore from a drop database command using a mysql binary log?
How can I restore a mysql database that was dropped using a "drop database" command?如何恢复使用“drop database”命令删除的 mysql 数据库? I have access to binary logs which should make this type of rollback possible.
我可以访问二进制日志,这应该使这种类型的回滚成为可能。
Documentation Sucks.文档很烂。 It alludes to DROP DATABASE being recoverable, but only in odd conditions i'm not familiar with http://dev.mysql.com/doc/refman/5.0/en/binary-log.html
它暗示 DROP DATABASE 是可恢复的,但仅在奇怪的情况下我不熟悉http://dev.mysql.com/doc/refman/5.0/en/binary-log.html
According to Docs, binlogs are just a sequence of commands executed based on a given reference point.根据 Docs,binlog 只是基于给定参考点执行的一系列命令。 So that when you did "DROP DATABASE", instead of going "Oh, hes droppping the database, we should back up now just in case" it merely wrote a "DROP DATABASE" to the last binlog.
所以当你执行“DROP DATABASE”时,而不是“哦,他正在删除数据库,我们现在应该备份以防万一”它只是在最后一个二进制日志中写了一个“DROP DATABASE”。 Recovery is not as simple as playing the tape backwards.
恢复并不像倒放磁带那么简单。
What you need to do is recover the database from a last-known-good, and apply the binlogs that happened between that recover point and the DROP command.您需要做的是从最后一个已知良好状态恢复数据库,并应用在该恢复点和 DROP 命令之间发生的二进制日志。
http://dev.mysql.com/doc/refman/5.0/en/recovery-from-backups.html http://dev.mysql.com/doc/refman/5.0/en/recovery-from-backups.html
How one determines which binlogs to use tho, unclear.如何确定使用哪些二进制日志,尚不清楚。
There is nothing better than having full file system backups.没有什么比拥有完整的文件系统备份更好的了。 And you should at least have these to fall back to.
你至少应该有这些可以回退。
If you don't have a backup of the database, you're out of luck.如果您没有数据库备份,那您就不走运了。 Drop ing a database is permanent.
删除数据库是永久性的。
Assuming you had a backup, the binary log holds the stuff that has happened since that backup.假设你有一个备份,二进制日志保存了自备份以来发生的事情。 Using the mysqlbinlog utility you could do something like:
使用 mysqlbinlog 实用程序,您可以执行以下操作:
mysqlbinlog the_log_file > update.sql mysqlbinlog the_log_file > update.sql
Though I think you might have to edit that file to remove anything you didn't want to execute again (like the drop database statement).虽然我认为您可能必须编辑该文件以删除您不想再次执行的任何内容(例如 drop database 语句)。
Good luck!祝你好运!
No backup no party.没有备份没有派对。
So I'll answer:那我来回答:
To never be in your situation again install the ultra simple and ultra powerful automysqlbackup (if you're on linux):为了不再遇到这种情况,请安装超简单且超强大的 automysqlbackup(如果您使用的是 linux):
sudo apt-get install automysqlbackup sudo apt-get install automysqlbackup
configure it:配置它:
sudo nano /etc/default/automysqlbackup须藤纳米 /etc/default/automysqlbackup
Then upload its content automatically to dropbox, ubuntu one or similar.然后将其内容自动上传到 dropbox、ubuntu 或类似的。
Only then live happily :)只有这样才能快乐地生活:)
只是为了补充 Kent Fredric 的回答,如果您自数据库创建以来使用二进制日志记录,则可以回滚drop database
命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.