| MySQL OPTMIZE TABLE command is used to | | | | these steps in order:o Check database table for |
| de-fragment a MySQL table and thus reclaim its | | | | consistency. To do so, execute CHECK TABLE |
| unused space. You generally use this command | | | | command with following syntax: |
| when you delete a large part of the particular | | | | CHECK TABLE table_name |
| table or make several changes to it with | | | | Before running the command, make sure that |
| variable-length rows. But while the OPTMIMIZE | | | | you are connected to the server. The command |
| TABLE command is running, the server should run | | | | can be used with options like QUICK, MEDIUM, |
| seamlessly. Any interruption while this process is | | | | FAST and CHANGED etc. If using MyISAM, you |
| running could cause database to corrupt. In such | | | | can also use myisamchk command-line utility.o If |
| situations, you either require using your recent | | | | the above check reports corruption, next you |
| data backup or commercial MySQL Database | | | | should repair the database table using following |
| Recovery tools. | | | | command: |
| As an example, you run OPTIMIZE TABLE | | | | REPAIR TABLE table_name |
| command on table 'A' and MySQL Server process | | | | This command accepts parameters like QUICK, |
| gets unexpectedly killed. The next time, when you | | | | EXTENDED and USE_FRM. In case of MyISAM |
| start the database, you find table 'A' giving | | | | database, you can use myisamchk utility with |
| corruption errors. Such errors also occur even if | | | | recovery option -r.o You should again verify the |
| use FLUSH TABLE (used to clear and reload | | | | database integrity using CHECKTABLE or |
| internal caches used by MySQL) command before | | | | myisamchk utility. If it still reports corruption, use |
| using OPTMIMIZE TABLE command. | | | | your recent database backup to restore.o If no |
| Cause | | | | clean backup is available, scan your database using |
| MySQL database table is corrupted due to | | | | third-party MySQL Recovery applications. Such |
| unexpected interruption while OPTIMIZE | | | | tools examine the corrupted database using |
| statement is de-fragmenting the database table. | | | | powerful scanning algorithms, repair it and restore |
| MySQL could not read such tables and gives | | | | it at a safe location. They provide you efficient |
| corruption errors. | | | | MySQL Database Recovery through interactive |
| Solution | | | | interface. |
| To fix such corruption errors, you should follow | | | | |