zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

查询mysql数据库的容量和指定库中表的大小

mysql数据库 查询 指定 大小 容量
2023-09-27 14:22:13 时间

1.1查询指定数据库容量的大小

use information_schema;

select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='bike_order';

1.2.查询指定库中指定表的大小

use information_schema;

select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='baojia_bike' and table_name='bike';

1.3.查看一个连接中所有数据库的大小

use information_schema;

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;

1.4 查看制定数据库中所有表的大小

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='fan_intelligent'
order by data_length desc, index_length desc;