查询所有数据库占用磁盘空间大小的SQL语句:
语句如下
1
2
3
4
5
|
select
TABLE_SCHEMA, concat(truncate(
sum
(data_length)
/1024/1024
,2),
' MB'
) as data_size,
concat(truncate(
sum
(index_length)
/1024/1024
,2),
'MB'
) as index_size
from information_schema.tables
group by TABLE_SCHEMA
order by data_length desc;
|
执行结果如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
mysql>
select
TABLE_SCHEMA, concat(truncate(
sum
(data_length)
/1024/1024
,2),
' MB'
) as data_size,
concat(truncate(
sum
(index_length)
/1024/1024
,2),
'MB'
) as index_size
from information_schema.tables
group by TABLE_SCHEMA
order by data_length desc;
+--------------------+------------+------------+
| TABLE_SCHEMA | data_size | index_size |
+--------------------+------------+------------+
| shdx | 1042.38 MB | 258.97MB |
| mysql | 0.52 MB | 0.08MB |
| information_schema | 0.00 MB | 0.00MB |
+--------------------+------------+------------+
3 rows
in
set
mysql>
|
查询单个库中所有表磁盘占用大小的SQL语句:
执行语句如下
1
2
3
4
5
|
select
TABLE_NAME, concat(
truncate
(data_length/1024/1024,2),
' MB'
)
as
data_size,
concat(
truncate
(index_length/1024/1024,2),
' MB'
)
as
index_size
from
information_schema.tables
where
TABLE_SCHEMA =
'TestDB'
group
by
TABLE_NAME
order
by
data_length
desc
;
|
以上语句测试有效,注意替换以上的TestDB为数据库名
执行结果如下,截取部分
mysql>
select
TABLE_NAME, concat(
truncate
(data_length/1024/1024,2),
' MB'
)
as
data_size,
concat(
truncate
(index_length/1024/1024,2),
' MB'
)
as
index_size
from
information_schema.tables
where
TABLE_SCHEMA =
'shdx'
group
by
TABLE_NAME
order
by
data_length
desc
;
+
--------------------------------+-----------+------------+
| TABLE_NAME | data_size | index_size |
+
--------------------------------+-----------+------------+
| tab_automatch_log | 499.08 MB | 95.03 MB |
| tab_fundlog201505 | 101.96 MB | 19.13 MB |
| tab_online | 63.49 MB | 14.32 MB |
| tab_game_record201505 | 56.97 MB | 30.93 MB |
| tab_user | 52.17 MB | 12.31 MB |
| dc_user_action_active | 39.94 MB | 0.00 MB |
| tab_gametime_day | 37.22 MB | 21.50 MB |
| tab_fundlog | 35.12 MB | 6.45 MB |
| tab_game_record | 19.85 MB | 10.56 MB |
| tab_feeaccount | 19.17 MB | 10.75 MB |
| tab_userinfo | 18.78 MB | 6.33 MB |
| tab_userfund | 17.91 MB | 9.51 MB |
| tab_click_count | 14.63 MB | 1.75 MB |
| tab_achievement_log | 10.51 MB | 1.36 MB |
| tab_gameloginlog201505 | 5.78 MB | 0.75 MB |
| tab_gametime | 4.29 MB | 3.16 MB |
| tab_gameloginlog | 3.83 MB | 0.50 MB |
| tab_login_log201505 | 2.79 MB | 0.67 MB |
| tab_system_operatelog | 2.74 MB | 0.19 MB |
| tab_singleplay_score | 2.10 MB | 0.28 MB |
| tab_game_record201301 | 1.93 MB | 1.08 MB |
| tab_game_score_shddz | 1.61 MB | 0.80 MB |
| tab_game_score_ddz | 1.39 MB | 0.66 MB |
| tab_game_score_shmj | 1.34 MB | 0.67 MB |
| tab_game_xyzdx_getscore_detail | 1.28 MB | 0.21 MB |