It is a good idea to perform table checks on a regular basis rather than waiting for problems to occur. One way to check and repairMyISAM tables is with theCHECK TABLE andREPAIR TABLE statements. SeeTable Maintenance Statements.
Another way to check tables is to usemyisamchk. For maintenance purposes, you can usemyisamchk -s. The-s option (short for--silent) causesmyisamchk to run in silent mode, printing messages only when errors occur.
It is also a good idea to enable automaticMyISAM table checking. For example, whenever the machine has done a restart in the middle of an update, you usually need to check each table that could have been affected before it is used further. (These are“expected crashed tables.”) To cause the server to checkMyISAM tables automatically, start it with themyisam_recover_options system variable set. SeeServer System Variables.
You should also check your tables regularly during normal system operation. For example, you can run acron job to check important tables once a week, using a line like this in acrontab file:
35 0 * * 0/path/to/myisamchk --fast --silent/path/to/datadir/*/*.MYIThis prints out information about crashed tables so that you can examine and repair them as necessary.
To start with, executemyisamchk -s each night on all tables that have been updated during the last 24 hours. As you see that problems occur infrequently, you can back off the checking frequency to once a week or so.
Normally, MySQL tables need little maintenance. If you are performing many updates toMyISAM tables with dynamic-sized rows (tables withVARCHAR,BLOB, orTEXT columns) or have tables with many deleted rows you may want to defragment/reclaim space from the tables from time to time. You can do this by usingOPTIMIZE TABLE on the tables in question. Alternatively, if you can stop themysqld server for a while, change location into the data directory and use this command while the server is stopped:
$> myisamchk -r -s --sort-index --myisam_sort_buffer_size=16M */*.MYI