InnoDB is designed for crash safety, but recovery after an unexpected shutdown still requires careful handling. Here is what happens during InnoDB crash recovery and how to handle edge cases.
How InnoDB Crash Recovery Works
InnoDB uses a write-ahead log (redo log) to replay committed transactions after a crash:
- MySQL starts and detects the redo log is dirty
- InnoDB replays all committed transactions from the redo log
- Uncommitted transactions are rolled back (undo log)
- The database opens for normal operation
Checking Recovery Status
-- After startup, check for recovery messages
SHOW ENGINE INNODB STATUS\G
-- Look for: '...started; log sequence number...'
-- and: 'Transaction list consists of X transactions'innodb_force_recovery Levels
When the database will not start, use innodb_force_recovery in my.cnf:
[mysqld]
innodb_force_recovery = 1 # Start even if redo log is corruptRecovery levels (use the lowest that works):
- 1: Skip corrupt pages, continue startup
- 2: Prevent background thread from running
- 3: Do not run transaction rollbacks
- 4: Disable insert buffer merge
- 5: Do not look at undo logs (skip incomplete transactions)
- 6: Skip corrupt pages even if detected
Emergency Dump Procedure
# With force_recovery set, dump all data
mysqldump --single-transaction --all-databases > emergency_dump.sql
# Check for errors in dump
grep -i error emergency_dump.sql
# Restore to fresh instance
mysql -u root -p < emergency_dump.sqlPreventing Future Crashes
[mysqld]
innodb_flush_log_at_trx_commit = 1 # ACID compliance
sync_binlog = 1 # Sync binlog on every commit
innodb_doublewrite = ON # Extra protection against partial writesKey Takeaways
- InnoDB recovery is automatic — most crashes recover without intervention
- Use the lowest
innodb_force_recoverylevel that allows startup - At level 3+, dump and restore immediately — do not run production
- Set
innodb_flush_log_at_trx_commit=1andsync_binlog=1for durability
JusDB Can Help
InnoDB crashes are stressful. JusDB provides emergency database recovery services and can help you prevent future incidents. Contact us for immediate assistance.