MyISAM stores table data in 3 separate files:

File

Purpose

table_name.frm

Table structure (columns, definitions)

table_name.MYD

Table data (all rows)

table_name.MYI

Table indexes (keys, cardinality, index blocks)


The .MYI file contains:

•All indexes for the table (PRIMARY, UNIQUE, INDEX, FULLTEXT)

•Index pages / B-tree blocks

•Key distribution statistics

•Cardinality estimates

•Auto-increment values (for MyISAM only)

•Repair information


Whenever you create an index on a MyISAM table, MySQL writes index structures into the .MYI file.

Because it stores the indexes, MyISAM reads it to:

•find rows quickly

•count distinct values

•compute cardinality

•maintain index ordering


If the .MYI file becomes fragmented or corrupted, queries slow down.


When does the .MYI file grow?

•Adding indexes

•Inserting many rows

•Updating indexed columns

•Deleting rows (leaves holes, causes fragmentation)


OPTIMIZE TABLE helps clean that up.


OPTIMIZE TABLE your_table;

REPAIR TABLE your_table;

ANALYZE TABLE your_table;



Topic last reviewed: 26/11/25