统计系统数据容量
MySQL数据库
- 查看所有数据库容量大小
1
2
3
4
5
6
7select table_schema as '数据库',
sum(table_rows) as '记录数',
sum(truncate(data_length / 1024 / 1024, 2)) as '数据容量(MB)',
sum(truncate(index_length / 1024 / 1024, 2)) as '索引容量(MB)'
from information_schema.tables
group by table_schema
order by sum(data_length) desc, sum(index_length) desc;
查看所有数据库各表容量大小
1
2
3
4
5
6
7select table_schema as '数据库',
table_name as '表名',
table_rows as '记录数',
truncate(data_length / 1024 / 1024, 2) as '数据容量(MB)',
truncate(index_length / 1024 / 1024, 2) as '索引容量(MB)'
from information_schema.tables
order by data_length desc, index_length desc;查看指定数据库容量大小
1
2
3
4
5
6select table_schema as '数据库',
sum(table_rows) as '记录数',
sum(truncate(data_length / 1024 / 1024, 2)) as '数据容量(MB)',
sum(truncate(index_length / 1024 / 1024, 2)) as '索引容量(MB)'
from information_schema.tables
where table_schema = 'mysql';查看指定数据库各表容量大小
1
2
3
4
5
6
7
8select table_schema as '数据库',
table_name as '表名',
table_rows as '记录数',
truncate(data_length / 1024 / 1024, 2) as '数据容量(MB)',
truncate(index_length / 1024 / 1024, 2) as '索引容量(MB)'
from information_schema.tables
where table_schema = 'mysql'
order by data_length desc, index_length desc;
MongoDB数据库
1 | db.stats(); |
默认返回数据单位是bytes
可以通过传参数,比如db.stats(1024)
得到的是kb单位
db.stats(1073741824);
得到的是G单位
1 | { |
这里的objects
以及avgObjSize
还是bytes
为单位的,不受参数影响