指令語法
SHOW TABLE STATUS FROM `database_name` [LIKE 'pattern']\G
\G 以垂直格式顯示,適合欄位較多時閱讀。
- 可加
LIKE 篩選表名模式。
輸出欄位完整說明
| 欄位 | 含義 |
| Name | 資料表名稱 |
| Engine | 儲存引擎 (MyISAM, InnoDB, MEMORY...) |
| Version | 表定義版本號 |
| Row_format | 列格式 (Fixed, Dynamic, Compressed, Redundant, Compact) |
| Rows | 預估行數 (InnoDB 為近似值) |
| Avg_row_length | 平均每列位元組數 |
| Data_length | 資料檔案大小 (bytes) |
| Max_data_length | 最大資料容量 (MyISAM 受限於指標大小) |
| Index_length | 索引檔案大小 (bytes) |
| Data_free | 已分配但未使用空間 (碎片) |
| Auto_increment | 下一個 AUTO_INCREMENT 值 |
| Create_time | 建立時間 |
| Update_time | 最後資料修改時間 |
| Check_time | 最後 CHECK TABLE 時間 |
| Collation | 字元集排序規則 |
| Checksum | 即時校驗和 (MyISAM) |
| Create_options | 建表額外選項 (如 partitioned, row_format=compressed) |
| Comment | 備註 (含表空間路徑等) |
實戰範例
mysql> SHOW TABLE STATUS FROM mysql\G
*************************** 1. row ***************************
Name: columns_priv
Engine: MyISAM
Version: 10
Row_format: Fixed
Rows: 0
Avg_row_length: 0
Data_length: 1024
Max_data_length: 254649548129
Index_length: 2048
Data_free: 0
Auto_increment: NULL
Create_time: 2023-01-15 10:30:00
Update_time: 2023-01-15 10:30:00
Check_time: NULL
Collation: utf8_bin
Checksum: NULL
Create_options:
Comment:
...
常見用途
- 快速掌握資料表大小、引擎、自增值、碎片程度。
- 判斷是否需
OPTIMIZE TABLE 整理碎片 (Data_free 過大)。
- 檢查
Auto_increment 接近上限風險。
- 比對主從同步時的
Update_time / Check_time。
相關指令
SHOW TABLE STATUS LIKE 'prefix%' 篩選前綴。
SHOW TABLE STATUS WHERE Engine='InnoDB' (MySQL 5.0+ 支援 WHERE)。
INFORMATION_SCHEMA.TABLES 標準 SQL 查詢方式,功能更強。