Skip to content

Instantly share code, notes, and snippets.

@dubcl
Created July 13, 2020 20:18
Show Gist options
  • Save dubcl/e227e8f0587530ca91eaab0621345e01 to your computer and use it in GitHub Desktop.
Save dubcl/e227e8f0587530ca91eaab0621345e01 to your computer and use it in GitHub Desktop.
innodb force recovery
FROM: https://serverfault.com/questions/592793/mysql-crashed-and-wont-start-up
Ouch.
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/forcing-recovery.html
InnoDB: about forcing recovery.
Check the suggested webpage: http://dev.mysql.com/doc/refman/5.1/en/forcing-recovery.html.
Basically, try to start the MySQL server in a recovery mode and make a backup of your crashed tables.
Edit your /etc/my.cnf and add:
innodb_force_recovery = 1
...to see if you can get into your database and get your data / find the corrupted table.
Usually, when this happens it's a re-build (at least of a corrupted table or two).
From http://chepri.com/mysql-innodb-corruption-and-recovery/:
Stop mysqld (service mysql stop).
Backup /var/lib/mysql/ib*
Add the following line into /etc/my.cnf:
innodb_force_recovery = 1
(they suggest 4, but its best to start with 1 and increment if it won't start)
Restart mysqld (service mysql start).
Dump all tables: mysqldump -A > dump.sql
Drop all databases which need recovery.
Stop mysqld (service mysql stop).
Remove /var/lib/mysql/ib*
Comment out innodb_force_recovery in /etc/my.cnf
Restart mysqld. Look at mysql error log. By default it should be /var/lib/mysql/server/hostname.com.err to see how it creates new ib* files.
Restore databases from the dump: mysql < dump.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment