Howto/20120923 Repair corrupt MySQL database that won't start

From Interpause
Jump to navigationJump to search

Sources:

Steps

  • Always check log files first for suggestions, /var/log/mysql/
  • Try to repair the database offline, in a shell run:
sudo myisamchk --force --update-state --key_buffer_size=64M \
--sort_buffer_size=64M --read_buffer_size=1M \
--write_buffer_size=1M /var/lig/mysql/*/*.MYI
  • Reboot and test that the database is online.
  • If database still offline, edit /etc/mysql/my.cnf, and add the following line to section [mysqld]
innodb_force_recovery = 6 # Should try 1 to 6 in increasing numbers
  • Reboot and test that the database is online. Note: Database should be online but the innoDB is still corrupt and must be fixed!
  • Create a dump of the sql database
sudo mysqldump -u root -p--all-databases > ~/backup.sql
  • Delete the ibdata and ib_logfile files
sudo rm /var/lib/mysql/ibdata1
sudo rm /var/lib/mysql/ib_logfile*
  • Remove the recovery mode, by commenting the previously added line:
# innodb_force_recovery = 6 # Should try 1 to 6 in increasing numbers
  • Reboot and test that the database is online.
  • Restore the dump
sudo mysql -u root -p < ~/backup.sql

or from mysql:

mysql> source backup.sql