美文网首页日更成长营js css htmlMysql
查看MySQL数据库表容量大小

查看MySQL数据库表容量大小

作者: 小强聊成长 | 来源:发表于2022-12-27 14:23 被阅读0次

作为DBA肯定要经常了解数据库的空间剩余大小和表空间使用情况。

使用navicat直接查看,不能直观的显示所有的表记录数和空间大小使用情况,一般文本记录数多,但是占用空间比较大的还是图片和文件的。

如何查询可以显示所有的表空间记录数和表占用空间大小的排名。可以使用下面的语句:

查看所有数据库容量大小

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;

查看所有数据库各表容量大小

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;

如果你有多个数据库,想要查指定某个数据库的大小,可以使用下面的语句:

查看指定数据库容量大小

例:查看mydb库容量大小

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='mydb';

查看指定数据库各表容量大小

例:查看mydb库各表容量大小

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='mydb'

order by data_length desc, index_length desc;

________________END______________

相关文章

网友评论

    本文标题:查看MySQL数据库表容量大小

    本文链接:https://www.haomeiwen.com/subject/lxkrqdtx.html