MySQL won’t start after power loss

So I had a power outage this week and my Pi server restarted, after reboot I noticed that WordPress wouldn’t start anymore. Starting mysqld manually would cause the following error:

03:02:19 UTC – mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.

Most pages returned by Google say that the InnoDB is probably corrupted and suggest to force recovery in my.cnf using the flag

innodb_force_recovery = 4

The innodb_force_recovery takes a number from 1 to 6.

However, none of these options could get mysqld to start, I was always getting the same error.

Here is what I did to get it to work:

  1. In my.cnf add innodb_force_recovery = 6 in the [mysqld] section (mySQL manual)
  2. In my.cnf add innodb_purge_threads=0 (this what allowed mysqld to start in read only mode)
  3. Start mysqld (“mysqld –verbose” or “/etc/init.d/mysqld start”)
  4. Check for corruption: mysqlcheck -p –all-databases
  5. Find the corrupt table and do: myisamchk -r -v -f <table_name> (where the data file is stored)
  6. Using the mysql recovery command did not fix anything, it was unable to recover the error, but you are welcome to try
  7. Backup your data: mysqldump -A > /home/user/backup_dump.sql
  8. Stop mysqld
  9. Delete /var/lib/mysql/ib*
  10. Comment the 2 lines you added in my.cnf
  11. Restart my mysqld
  12. Restore from the SQL dump if needed