转:mysql查看表大小

原文:mysql查看表大小

use information_schema;


-- 查看 各库 占用 大小
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;

-- 查看某个库 各表 占用 情况 (database_name---->为你要查询的数据库名称)
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 = 'database_name'
group by TABLE_NAME
order by data_length desc;

-- 查看 某个库 某个表 占用 情况 (database_name-:数据库名称,  tablename: 表名 )
select table_name,concat(round(sum(data_length/1024/1024),2),'MB') as data
from tables where table_schema='database_name'
and table_name='tablename'; 

posted @ 2023-12-21 11:26  jiafeng  阅读(12)  评论(0编辑  收藏  举报