Linux : MySQL table is marked as crashed and should be repaired

By | April 2, 2017

Slow MySQL server, with very high load and consuming a lot of I/O without any particular reason? If you see the following error when looking at the MySQL log file (/var/lib/mysql.log), then now you know why!

[ERROR] /usr/libexec/mysqld: Table ‘./database_name/table_name’ is marked as crashed and should be repaired

Fortunately, this issue is probably easy fixable by using the MySQL repair tool. Assuming you already have backups (if you don’t, shame on you and take one right away!) and then, follow these steps to resolve this issue :

  • Invoke the repair tool for the database specified to have crashed table (replace <USER> by a user that have server administrative privileges) :
mysqlcheck -u <USER> -p --repair database_name

NOTE : If there is a lot of damaged tables, you might need to append the “–extended” option after “–repair”.

This step might take a while, I would recommend running it under a “screen” session if you are working remotely to avoid this process to be interrupted if your session get cut, this might damage the database even more.

  • If you are recovering for a major crash and many databases are shown to be affected in the log, you may use this command to check them all at once :
mysqlcheck -u <USER> -p --repair --all-databases