MySQL

MySQL InnoDB Crash Recovery: Diagnosis and Emergency Procedures

Understand InnoDB crash recovery mechanics and handle edge cases with innodb_force_recovery. Emergency dump procedures and durability settings to prevent future crashes.

JusDB Team
February 17, 2025
5 min read
133 views

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:

  1. MySQL starts and detects the redo log is dirty
  2. InnoDB replays all committed transactions from the redo log
  3. Uncommitted transactions are rolled back (undo log)
  4. The database opens for normal operation

Checking Recovery Status

sql
-- 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:

ini
[mysqld]
innodb_force_recovery = 1   # Start even if redo log is corrupt

Recovery 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
Important: At level 3+, data loss is likely. Dump your data immediately and restore to a clean instance. Never run production on force recovery > 3.

Emergency Dump Procedure

bash
# 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.sql

Preventing Future Crashes

ini
[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 writes

Key Takeaways

  • InnoDB recovery is automatic — most crashes recover without intervention
  • Use the lowest innodb_force_recovery level that allows startup
  • At level 3+, dump and restore immediately — do not run production
  • Set innodb_flush_log_at_trx_commit=1 and sync_binlog=1 for 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.

Share this article

JusDB Team

Official JusDB content team