MySQL - Autorepair Corrupted Database Using mysqlcheck command

One or more tables within a MySQL database may get corrupted for certain reason.1 Then your application will fail to work when it try to access these corrupted tables. In this article you will see simple commands that can be used to automatically repair that corrupted tables.

You can recover most of these corrupted tables by running a simple command involving mysqlcheck. The whole database can be checked and each corrupted tables can repaired automatically whenever possible using the following command:

mysqlcheck --auto-repair -u root -p databasename

Or if you just want to perform the check and repair only on one or few tables. Then those table names can be given.

mysqlcheck --auto-repair -u root -p databasename table1 table2

For non-corrupted tables, output will be a line like:

databasename.table5                          OK

For corrupted tables, it will output messages like given below when repair gone success.

Repairing tables
databasename.table1
warning  : Number of rows changed from 916 to 921
status   : OK
databasename.table2
warning  : Number of rows changed from 973 to 985
status   : OK

  1. Some events which will cause the tables to be corrupted are given in this page: http://dev.mysql.com/doc/refman/5.1/en/corrupted-myisam-tables.html