Press "Enter" to skip to content

Mysql查看某个表的大小

查看所有库的大小
mysql> use information_schema;
Database changed
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES;
+----------+
| data |
+----------+
| 100MB |
+----------+
1 row in set (0.11 sec)

查看指定库的大小
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='testdb';
+---------+
| data |
+---------+
| 100MB |
+---------+
1 row in set (0.01 sec)

查看指定库的指定表的大小
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='testdb' and table_name='test';
+--------+
| data |
+--------+
| 100MB |
+--------+
1 row in set (0.00 sec)

查看指定库的索引大小
mysql> SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), ' MB') AS 'Total Index Size' FROM TABLES WHERE table_schema = 'testdb';
+------------------+
| Total Index Size |
+------------------+
| 20 MB |
+------------------+
1 row in set (0.01 sec)

查看指定库的指定表的索引大小
mysql> SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), ' MB') AS 'Total Index Size' FROM TABLES WHERE table_schema = 'testdb' and table_name='test';
+------------------+
| Total Index Size |
+------------------+
| 20 MB |
+------------------+
1 row in set (0.00 sec)

查看一个库中的情况
mysql> SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows/1000000,4),'M') AS 'Number of Rows', CONCAT(ROUND(data_length/(1024*1024*1024),4),'G') AS 'Data Size', CONCAT(ROUND(index_length/(1024*1024*1024),4),'G') AS 'Index Size', CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),4),'G') AS'Total'FROM information_schema.TABLES WHERE table_schema LIKE 'testdb';
+---------------+----------------+-----------+------------+---------+
| Table Name | Number of Rows | Data Size | Index Size | Total |
+---------------+----------------+-----------+------------+---------+
| testdb.table1 | 0.4625M | 0.0259G | 0.0171G | 0.0431G |
| testdb.table2 | 0.7099M | 0.0660G | 0.0259G | 0.0919G |
+---------------+----------------+-----------+------------+---------+
4 rows in set (0.13 sec)

One Comment

发表评论

电子邮件地址不会被公开。 必填项已用*标注