为了合并碎片化的行并消除因删除或更新行而产生的浪费空间,请在恢复模式下运行 myisamchk:To coalesce fragmented rows and eliminate wasted space that results from deleting or updating rows, run myisamchk in recovery mode:
$> myisamchk -r tbl_name
您可以通过使用 OPTIMIZE TABLE SQL 语句以同样的方式优化表。OPTIMIZE TABLE 会对表进行修复和索引分析,还会对索引树进行排序,从而加快键查找速度。使用 OPTIMIZE
TABLE 时,服务器会完成所有工作,因此不存在实用工具与服务器之间的意外交互的可能性。参见 第 15.7.3.4 节,“OPTIMIZE TABLE 语句”。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 15.7.3.4, “OPTIMIZE TABLE Statement”.
myisamchk 有许多其他选项可以用来提高表的性能:myisamchk has a number of other options that you can use to improve the performance of a table:
--analyze或-a:执行键分布分析。这通过使连接优化器能够更好地选择表的连接顺序以及使用哪些索引,从而提高连接性能。--analyzeor-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.--sort-index或-S:排序索引块。这优化了查找操作,并加快了使用索引的表扫描速度。--sort-indexor-S: Sort the index blocks. This optimizes seeks and makes table scans that use indexes faster.--sort-records=或index_num-R:根据给定的索引对数据行进行排序。这会使您的数据更加本地化,并可能加快使用此索引的基于范围的index_numSELECT和ORDER BY操作。--sort-records=orindex_num-R: Sort data rows according to a given index. This makes your data much more localized and may speed up range-basedindex_numSELECTandORDER BYoperations that use this index.
有关所有可用选项的完整说明,请参见 第 6.6.4 节,“myisamchk — MyISAM 表维护工具”。For a full description of all available options, see Section 6.6.4, “myisamchk — MyISAM Table-Maintenance Utility”.