MyISAM Table Optimization Note If you want a repair operation to go much faster, you should set the values of the sort_buffer_size  and  key_buffer_size  variables each to about 25% of your available memory when running  myisamchk . If you get unexpected errors when repairing (such as  out of memory  errors), or if  myisamchk  crashes, go to Stage 3. Stage 3: Difficult repair 7.6.4 MyISAM Table Optimization 1634 shell>  myisamchk -r  tbl_name mysql>  SET autocommit=1; mysql>  TRUNCATE TABLE  tbl_name ; mysql>  quit shell>  mysql  db_name You should reach this stage only if the first 16KB block in the index file is destroyed or contains incorrect information, or if the index file is missing. In this case, it is necessary to create a new index file. Do so as follows: If you are using replication, you should stop it prior to performing the above procedure, since it involves file system operations, and these are not logged by MySQL. Go back to Stage 2.  myisamchk -r -q  should work. (This should not be an endless loop.) You can also use the  REPAIR TABLE  tbl_name  USE_FRM  SQL statement, which performs the whole procedure automatically. There is also no possibility of unwanted interaction between a utility and the server, because the server does all the work when you use  REPAIR TABLE . See Section 13.7.3.5, “REPAIR TABLE Statement” . To coalesce fragmented rows and eliminate wasted space that results from deleting or updating rows, run myisamchk  in recovery mode: You can optimize a table in the same way by using the  OPTIMIZE TABLE  SQL statement.  OPTIMIZE TABLE  does a table repair and a key analysis, and also sorts the index tree so that key lookups are faster. There is also no possibility of unwanted interaction between a utility and the server, because the server does all the work when you use  OPTIMIZE TABLE . See Section 13.7.3.4, “OPTIMIZE TABLE Statement” . myisamchk  has a number of other options that you can use to improve the performance of a table: • --analyze  or  -a : Perform key distribution analysis. This improves join performance by enabling the join optimizer to better choose the order in which to join the tables and which indexes it should use. 3. Copy the old data file back onto the newly created data file. (Do not just move the old file back onto the new file. You want to retain a copy in case something goes wrong.) Important 1. Move the data file to a safe place. 2. Use the table description file to create new (empty) data and index files: