当前位置:网站首页>查看数据库数据量大小,占用磁盘大小
查看数据库数据量大小,占用磁盘大小
2022-08-02 17:33:00 【Direct_】
文章目录
查看数据库数据量大小,占用磁盘大小
本次测试使用
mysql
数据库
数据库名demo
1. 查看现有数据库
show databases;
2. 进入information_schema 数据库(存放了其他的数据库的信息)
use information_schema;
3. 查看 information_schema 数据库表信息
select * from information_schema.tables;
4. 查询所有数据的总大小:
select concat(round(sum(data_length/1024/1024),2),'MB') as data from information_schema.tables;
5. 查看实例下所有数据库的空间占用情况,并按从大小排序
select table_schema ,concat(round(sum(data_length/1024/1024),2),'MB') as data from information_schema.tables where table_schema like '%%' group by table_schema order by data desc;
6.查看指定数据库的大小:
select concat(round(sum(data_length/1024/1024),2),'MB') as data from information_schema.tables where table_schema='demo' ;
7. 查看指定数据库下的所有表的空间占用情况,并按从大到小排序
select table_name,round(sum(data_length/1024/1024),2) as size from information_schema.tables where table_schema='demo' group by table_name order by size desc;
8. 查看指定数据库的某个表的大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from information_schema.tables where table_schema='demo' and table_name='t_student' ;
其他
select table_schema ,
round(sum(data_length/1024/1024),2) as data_length ,
round(sum(DATA_FREE/1024/1024),2) as data_free ,
round(sum(INDEX_LENGTH/1024/1024),2) as INDEX_LENGTH from information_schema.tables where table_schema='demo' group by table_schema order by data_length;
select
TABLE_SCHEMA
,sum(DATA_LENGTH)/1024/1024/1024 as size_DATA_LENGTH_g
,sum(INDEX_LENGTH)/1024/1024/1024 as size_INDEX_LENGTH_g
,sum(DATA_FREE)/1024/1024/1024 as size_DATA_FREE_g
,sum((DATA_LENGTH+INDEX_LENGTH+DATA_FREE))/1024/1024/1024 as size_g
from information_schema.tables
where table_type = 'BASE TABLE'
group by TABLE_SCHEMA
order by size_DATA_FREE_g
;
select
TABLE_NAME
,sum(DATA_LENGTH)/1024/1024/1024 as size_DATA_LENGTH_g
,sum(INDEX_LENGTH)/1024/1024/1024 as size_INDEX_LENGTH_g
,sum(DATA_FREE)/1024/1024/1024 as size_DATA_FREE_g
,sum((DATA_LENGTH+INDEX_LENGTH+DATA_FREE))/1024/1024/1024 as size_g
from information_schema.tables
where table_type = 'BASE TABLE'
and table_schema = 'db_name'
– and TABLE_NAME = 'table_name'
group by TABLE_NAME
order by size_g desc
limit 20
边栏推荐
猜你喜欢
MySQL索引
动力电池扩产潮,宁德时代遭围剿
MySQL基本语法
融云「 IM 进阶实战高手课」系列直播上线
How Tencent architects explained: The principle of Redis high-performance communication (essential version)
小程序毕设作品之微信体育馆预约小程序毕业设计成品(6)开题答辩PPT
深圳地铁16号线二期进入盾构施工阶段,首台盾构机顺利始发
文件上传很难搞?10分钟带你学会阿里云OSS对象存储
Smart Contract Security - delegatecall (1)
golang学习之七:并发编程基础(goroutine、channel、select)
随机推荐
MySQL常见面试题汇总(建议收藏!!!)
一篇文章带你搞定BFC~
用函数递归的方法解决汉诺塔问题
9月起中国给予多哥等16国98%税目产品零关税待遇
使用lodash替换js字符串中的变量
LeetCode·每日一题·
暴跌99.7%后,谁还在买卖「二舅币」?
土巴兔IPO五次折戟,互联网家装未解“中介”之痛
分布式 | dble 启动的时候做了什么之配置检测
Inconsistency between oracle and mysql statement results
年轻人接棒大妈,金价跌回“4字头”,七夕迎黄金消费小热潮
golang源码分析(9)调度
Informatica旗下PowerCenter的元数据库解析
LeetCode·76.最小覆盖子串·滑动窗口
vulnhub W34kn3ss: 1
golang源码分析(8):m、p、g、shedt、sudog
[300+ selected big factory interview questions continue to share] Big data operation and maintenance sharp knife interview questions column (10)
Pytest study notes
白话电子签章原理及风险
Red and blue against experience sharing: CS from kill posture