It is a good idea to perform table checks on a regular basis rather than
waiting for problems to occur. For maintenance purposes, you can use
isamchk -s to check tables. The -s option causes
isamchk to run in silent mode, printing messages only when errors
occur.
It's a good idea to check tables when the server starts up.
For example, whenever the machine has done a reboot in the middle of an
update, you usually need to check all the tables that could have been
affected. (This is an ``expected crashed table''.) You could add a test to
safe_mysqld that runs isamchk to check all tables that have
been modified during the last 24 hours if there is an old `.pid'
(process ID) file left after a reboot. (The `.pid' file is created by
mysqld when it starts up and removed when it terminates normally. The
presence of a `.pid' file at system startup time indicates that
mysqld terminated abnormally.)
An even better test would be to check any table whose last-modified time is more recent than that of the `.pid' file.
You should also check your tables regularly during normal system operation.
At TcX, we run a cron job to check all our important tables once a week,
using a line like this in a `crontab' file:@:
35 0 clean_docs_mysql clean_docs-php debut.php fin.php index.php menu.php mysql php clean_docs_mysql clean_docs-php debut.php fin.php index.php menu.php mysql php 0 /path/to/isamchk -s /path/to/datadir/*/*.ISM
This prints out information about crashed tables so we can examine and repair them when needed.
As we haven't had any unexpectedly crashed tables (tables that become corrupted for reasons other than hardware trouble) for a couple of years now (this is really true), once a week is more than enough for us.
We recommend that to start with, you execute isamchk -s each
night on all tables that have been updated during the last 24 hours,
until you come to trust MySQL as much as we do.