MariaDB on Raspberry PI won’t start

The summary of the error encountered is: LSB: Start and stop the mysql database server daemon

Running service mysql status outputs:

● mysql.service - LSB: Start and stop the mysql database server daemon
   Loaded: loaded (/etc/init.d/mysql)
   Active: activating (start) since Thu 2017-01-19 17:30:05 EET; 15s ago
  Control: 4205 (mysql)
   CGroup: /system.slice/mysql.service
           ├─4205 /bin/bash /etc/init.d/mysql start
           └─4510 sleep 1

Jan 19 17:30:06 pi mysqld[4370]: InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it.
Jan 19 17:30:06 pi mysqld[4370]: InnoDB: To fix the problem and start mysqld:
Jan 19 17:30:06 pi mysqld[4370]: InnoDB: 1) If there is a permission problem in the file and mysqld cannot
Jan 19 17:30:06 pi mysqld[4370]: InnoDB: open the file, you should modify the permissions.
Jan 19 17:30:06 pi mysqld[4370]: InnoDB: 2) If the table is not needed, or you can restore it from a backup,
Jan 19 17:30:06 pi mysqld[4370]: InnoDB: then you can remove the .ibd file, and InnoDB will do a normal
Jan 19 17:30:06 pi mysqld[4370]: InnoDB: crash recovery and ignore that table.
Jan 19 17:30:06 pi mysqld[4370]: InnoDB: 3) If the file system or the disk is broken, and you cannot remove
Jan 19 17:30:06 pi mysqld[4370]: InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf
Jan 19 17:30:06 pi mysqld[4370]: InnoDB: and force InnoDB to continue crash recovery here.

To fix this issue:

  • remember to make backups of your databases after using the following:
    sudo nano /etc/mysql/my.cnf
    innodb_force_recovery=1
  • http://stackoverflow.com/questions/33829888/innodb-attempted-to-open-a-previously-opened-tablespace
  • http://blackbird.si/mysql-corrupted-innodb-tables-recovery-step-by-step-guide/
  • http://stackoverflow.com/questions/11990708/error-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysql

If nothing works, reinstall the server:

  • sudo apt-get purge mysql*
  • sudo apt-get purge mariadb*
  • sudo apt-get autoremove
  • sudo apt-get autoclean
  • sudo apt-get dist-upgrade