mysql容量查询

查看所有数据库容量大小

1
2
3
4
5
6
7
8
select 
table_schema as `database`,
sum(table_rows) as `records`,
sum(truncate(data_length/1024/1024, 2)) as 'dataLength(MB)',
sum(truncate(index_length/1024/1024, 2)) as 'indexLength(MB)'
from information_schema.tables
group by table_schema
order by sum(data_length) desc, sum(index_length) desc;

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

1
2
3
4
5
6
7
8
select 
table_schema as 'database',
table_name as 'table_name',
table_rows as 'records',
truncate(data_length/1024/1024, 2) as 'dataLength(MB)',
truncate(index_length/1024/1024, 2) as 'indexLength(MB)'
from information_schema.tables
order by data_length desc, index_length desc;

查看指定数据库容量大小

1
2
3
4
5
6
7
select 
table_schema as 'database',
sum(table_rows) as 'records',
sum(truncate(data_length/1024/1024, 2)) as 'dataLength(MB)',
sum(truncate(index_length/1024/1024, 2)) as 'indexLength(MB)'
from information_schema.tables
where table_schema='mysql';

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

1
2
3
4
5
6
7
8
9
select 
table_schema as 'database',
table_name as 'table_name',
table_rows as 'records',
truncate(data_length/1024/1024, 2) as 'dataLength(MB)',
truncate(index_length/1024/1024, 2) as 'indexLength(MB)'
from information_schema.tables
where table_schema='mysql'
order by data_length desc, index_length desc;
你是本站第位访客 本站访客数人次
Fork me on GitHub