您的位置:首页 > 数据库 > MySQL

【转】MySQL查看表占用空间大小(转)

2017-07-28 03:39 369 查看
//先进去MySQL自带管理库:information_schema
//自己的数据库:rokid_cas_music_test
//自己的表:data_song_thirdparty

mysql> use information_schema;
Database changed
mysql> select data_length,index_length
from information_schema.tables where table_schema='rokid_cas_music_test' and table_name = 'data_song_thirdparty';

+-------------+--------------+
| data_length | index_length |
+-------------+--------------+
| 15993798656 | 8825700352 |
+-------------+--------------+
1 row in set (0.00 sec)

row in set (0.02 sec)

mysql> select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB,
concat(round(sum(index_length/1024/1024),2),'MB') as index_length_MB
from information_schema.tables where
table_schema='rokid_cas_music_test'
and table_name = 'data_song_thirdparty';

+----------------+-----------------+
| data_length_MB | index_length_MB |
+----------------+-----------------+
| 15252.88MB | 8416.84MB |
+----------------+-----------------+
1 row in set (0.01 sec)

row in set (0.03 sec)


查询MySQL数据库中每个数据库数据和索引所占的数据大小,单位G,保留两位小数

select table_schema,round(sum(data_length)/1024/1024/1024,3) as datasize, round(sum(index_length)/1024/1024/1024,3) as indexsize
from information_schema.tables
where table_schema != 'information_schema' and table_schema != 'mysql' and table_schema != 'performance_schema'
group by table_schema
order by datasize desc;


查询MySQL数据库中每个表的数据和索引所占的数据大小,单位G,保留两位小数

select table_schema,table_name,round(sum(data_length)/1024/1024/1024,3) as datasize, round(sum(index_length)/1024/1024/1024,3) as indexsize
from information_schema.tables
where table_schema != 'information_schema' and table_schema != 'mysql' and table_schema != 'performance_schema'
group by table_schema,table_name
order by datasize desc;


【转自】:http://www.cnblogs.com/qq78292959/archive/2012/12/26/2833698.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: