Check table and index size in MySQL
Read table storage statistics to find which tables account for the most data and index space.
Check table and index size in MySQL
Section titled “Check table and index size in MySQL”SELECT TABLE_NAME AS table_name, TABLE_ROWS AS estimated_rows, DATA_LENGTH AS data_bytes, INDEX_LENGTH AS index_bytes, DATA_LENGTH + INDEX_LENGTH AS total_bytes, DATA_FREE AS free_bytesFROM information_schema.TABLESWHERE TABLE_SCHEMA = DATABASE() AND TABLE_TYPE = 'BASE TABLE'ORDER BY DATA_LENGTH + INDEX_LENGTH DESC;The query reports bytes for base tables in the current database. For InnoDB, interpret the columns as follows:
| Column | Meaning |
|---|---|
estimated_rows |
An estimate, rather than an exact row count |
data_bytes |
Space allocated to the clustered index, which stores table data |
index_bytes |
Space allocated to secondary indexes together |
total_bytes |
The sum of data and index space |
free_bytes |
Allocated but unused space reported for the tablespace |
Free space can belong to a shared tablespace. Do not sum it across tables as guaranteed recoverable disk space. Other storage engines give these statistics different meanings.
Do it in TableAI
Section titled “Do it in TableAI”- Open Admin › Storage on the target connection.
- Compare the tables’ data, index, and total sizes.
- Run the SQL above in the query editor when you need byte counts.
Use storage and maintenance for the available maintenance actions. Storage totals alone do not establish that a table needs maintenance.
Required privileges
Section titled “Required privileges”MySQL exposes table metadata according to your account’s permissions. If a table is missing, confirm access to that table before comparing totals.
No extension is needed. For an access error, use Admin data troubleshooting.
Related
Section titled “Related”Use find unused indexes for usage evidence, or diagnose performance to investigate a broader storage problem. Return to the MySQL overview.