mysql database error table is marked as crashed and should be repaired

error:

XXXXXX XX:XX:XX [ERROR] /usr/libexec/mysqld: Table ‘./database/table’ is marked as crashed and should be repaired

myisamchk(1) – MyISAM table-maintenance utility

· –recover, -r

Do a repair that can fix almost any problem except unique keys that are not unique
(which is an extremely unlikely error with MyISAM tables). If you want to recover
a table, this is the option to try first. You should try –safe-recover only if
myisamchk reports that the table cannot be recovered using –recover. (In the
unlikely case that –recover fails, the data file remains intact.)

If you have lots of memory, you should increase the value of
myisam_sort_buffer_size.

· –safe-recover, -o

Do a repair using an old recovery method that reads through all rows in order and
updates all index trees based on the rows found. This is an order of magnitude
slower than –recover, but can handle a couple of very unlikely cases that
–recover cannot. This recovery method also uses much less disk space than
–recover. Normally, you should repair first using –recover, and then with
–safe-recover only if –recover fails.

If you have lots of memory, you should increase the value of key_buffer_size.

(re)solution:

# service mysqld stop

# for tbl in `grep ‘ERROR.*Table’ ~mysql/$HOSTNAME.err | awk -F\’ ‘{print $2}’` ; do myisamchk –recover $tbl ; done

# service mysqld start