บทนำ
คำสั่ง SHOW TABLE STATUS แสดงข้อมูลสถิติของตาราง รวมถึงขนาดข้อมูล (Data_length), ขนาดดัชนี (Index_length), และพื้นที่ว่าง (Data_free)
รูปแบบการใช้งาน
SHOW TABLE STATUS LIKE 'yourTableName'\G
ตัวอักษร \G ทำให้แสดงผลแบบแนวตั้ง (Vertical Format) อ่านง่ายกว่าแบบตาราง
ตัวอย่างการสร้างตารางและเพิ่มข้อมูล
mysql> CREATE TABLE DemoTable (
-> Id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> CustomerName VARCHAR(20),
-> CustomerAge INT,
-> CustomerCountryName VARCHAR(20)
-> );
Query OK, 0 rows affected (0.75 sec)
mysql> INSERT INTO DemoTable(CustomerName, CustomerAge, CustomerCountryName)
-> VALUES('John', 24, 'US');
mysql> INSERT INTO DemoTable(CustomerName, CustomerAge, CustomerCountryName)
-> VALUES('Carol', 22, 'UK');
แสดงข้อมูลทั้งหมด
mysql> SELECT * FROM DemoTable;
ผลลัพธ์
+----+--------------+-------------+---------------------+
| Id | CustomerName | CustomerAge | CustomerCountryName |
+----+--------------+-------------+---------------------+
| 1 | John | 24 | US |
| 2 | Carol | 22 | UK |
+----+--------------+-------------+---------------------+
2 rows in set (0.00 sec)
คำสั่งตรวจสอบขนาดตาราง
mysql> SHOW TABLE STATUS LIKE 'DemoTable'\G
ผลลัพธ์
*************************** 1. row ***************************
Name: DemoTable
Engine: InnoDB
Version: 10
Row_format: Dynamic
Rows: 0
Avg_row_length: 0
Data_length: 16384
Max_data_length: 0
Index_length: 0
Data_free: 0
Auto_increment: NULL
Create_time: 2019-06-10 16:35:55
Update_time: NULL
Check_time: NULL
Collation: utf8_unicode_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.01 sec)
คอลัมน์สำคัญสำหรับขนาด
| คอลัมน์ | ความหมาย | หน่วย |
|---|---|---|
| Data_length | ขนาดข้อมูลจริง | Bytes |
| Index_length | ขนาดดัชนี | Bytes |
| Data_free | พื้นที่ว่างที่ถูกจองไว้แต่ยังไม่ใช้ | Bytes |
| Rows | จำนวนแถว (ประมาณการสำหรับ InnoDB) | - |
| Avg_row_length | ขนาดเฉลี่ยต่อแถว | Bytes |