mysql查询所有数据库和每个表磁盘所占空间大小容量的方法sql
程序员文章站
2024-02-23 10:30:46
...
查询mysql所有数据库和每个表磁盘所占空间大小容量的方法sql
查询所有数据库占用磁盘空间大小的SQL语句如下:
select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2), 'MB') as data_size, concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables
group by TABLE_SCHEMA
order by data_length desc;
然后是查询单个数据库里面各个表所占磁盘空间大小包括其索引的大小,SQL语句如下:
select TABLE_NAME, concat(truncate(data_length/1024/1024,2),’ MB’) as data_size,
concat(truncate(index_length/1024/1024,2),’ MB’) as index_size
from information_schema.tables where TABLE_SCHEMA = ‘你数据库的名称’
group by TABLE_NAME
order by data_length desc;
mysql 查看数据库中所有表的记录数
use information_schema;
select table_name,table_rows from tables
where TABLE_SCHEMA = ‘you db name’
order by table_rows desc;