Introduction
In this article I describe how to check and repair a table when the server or operating system shuts down unexpectedly. The table in the database might become corrupted or the user of the database might not be able to access the table data. For those situations MySQL provides many of tools for determining which table needs repairs. In addition MySQL provides built-in tools to repair MyISAM tables.
Built-in tools
When it comes to repairing and checking tables, MySQL offers two options:
- The MySQL distribution ships with a tool called "myisamchk," designed specifically to check and repair MyISAM tables (the default table type used by MySQL). This tool can scan your databases, identify problems, optimize tables for faster lookup, and optionally repair corrupted tables. The myisamchk tool is invoked from the command line.
- MySQL also allows you check and repair tables using SQL commands. The CHECK TABLE, REPAIR TABLE, and OPTIMIZE TABLE commands can be used on a running MySQL server and need to be entered through a MySQL client.
So in this article, I am simply work with CHECK TABLE and REPAIR TABLE statements.
The check table statement is used to check tables, if the check table statement finds no problems with the tables then it will mark the table ok in the Msg_text column. The check table statement also reports if the table is "already update to date", it is not required to be checked.
Syntax
| CHECK TABLE table_list option_list |
Options for the CHECK TABLE statements:
| Option | Description |
| Extended | It provides the full scan of each row with ensuring that the table is 100% consistent but it requires a substantial amount of time. |
| Medium | It provides an average scan of each row; this option is the default for MyISAM tables. |
| Quick | It does a quick scan of the rows. |
| Fast | It only checks the tables that have not been closed properly. |
| Changed | It only checks the tables that have been changed since the last check option. |
| For Upgrade | It checks whether the tables are compatible with the current version of MySQL. |
The statements that check a single table
The following is an image of a query that checks a single table.
The statements that check a single table
The following is an image of a query that shows how to check multiple tables.


Join the conversation! Your thoughts help the community grow.