mysql查表空間大小的SQL語句

chenfeng發表於2016-03-01
SQL語句如下:

select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,
concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables where TABLE_SCHEMA = 'databasename';

例如查mysql資料庫表空間大小:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db_shop            |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.52 sec)


mysql>
mysql> select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
    -> concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,
    -> concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,
    -> concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
    -> from information_schema.tables where TABLE_SCHEMA = 'mysql';
+-----------+--------------------+-----------+------------+
| data_size | max_data_size      | data_free | index_size |
+-----------+--------------------+-----------+------------+
| 0.51MB    | 1938103992319.99MB | 0.00MB    | 0.09MB     |
+-----------+--------------------+-----------+------------+
1 row in set (1.49 sec)


mysql>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2021424/,如需轉載,請註明出處,否則將追究法律責任。

相關文章