Search code examples
mysqldatabaserecovery

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? I have access to binary logs which should make this type of rollback possible.


Solution

  • 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

    According to Docs, binlogs are just a sequence of commands executed based on a given reference point. 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. 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.

    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.