Toggle navigation
主页
English
K8S
Golang
Guitar
About Me
归档
标签
Welcome to Sanger's Blog!
MySQL查看数据库表容量大小
无
2022-04-07 10:50:55
21
0
0
sanger
[TOC] # MySQL查看数据库表容量大小 ## 查看一个数据中所有表的相关信息: (1)可以在命令下使用show table status \G命令查看: (2)如果想知道MySQL数据库中每个表占用的空间、表记录的行数的话,可以打开MySQL的 information_schema 数据库。在该库中有一个 TABLES 表,这个表主要字段分别是: TABLE_SCHEMA : 数据库名 TABLE_NAME:表名 ENGINE:所使用的存储引擎 TABLES_ROWS:记录数 DATA_LENGTH:数据大小 INDEX_LENGTH:索引大小 其他字段请参考MySQL的手册,我们只需要了解这几个就足够了。所以要知道一个表占用空间的大小,那就相当于是 数据大小 + 索引大小 即可。 ###1.查看所有数据库容量大小 ``` select 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; ``` ###2.查看所有数据库各表容量大小 ``` select 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; ``` ###3.查看指定数据库容量大小 例:查看mysql库容量大小 ``` select 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'; ``` ###4.查看指定数据库各表容量大小 例:查看mysql库各表容量大小 ``` select 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; ``` 参考: https://cloud.tencent.com/developer/article/1763354 https://www.cnblogs.com/dekevin/p/10276832.html https://blog.csdn.net/helloxiaozhe/article/details/88599777
上一篇:
Canal部署使用
下一篇:
nscd
0
赞
21 人读过
新浪微博
微信
更多分享
腾讯微博
QQ空间
人人网
文档导航