While working with a database, you do a lot of changes to tables such as inserting, updating and deleting data. This occupies disk space and deteriorates database performance. To handle this, periodic maintenance is required.
Allows you to optimize tables using the OPTIMIZE TABLE statement and sort out fragmented files for later use.
During the optimization, a read-only lock will be added to target tables. Therefore, optimizing tables during off-peak hours is recommended.
Allows you to check whether there are errors in database tables using the CHECK TABLE statement. You can check a table with any of the following methods:
The CHECK TABLE statement adds a read-only lock to the table.
Allows you to use the REPAIR TABLE statement to repair possibly corrupted or incorrect tables. You can repair tables using any of the following three methods:
Allows you to use the ANALYZE TABLE statement to analyze tables. During the analysis, read-only locks are added to tables. Tables can only be read during the analysis.
Temporary files will be generated during table optimization. These files may occupy twice the disk space of the current table data.
The following uses the Check operation as an example to explain how to maintain tables.