sql命令查询mysql数据使用磁盘空间大小

登录mysql

mysql -uroot -p;

进入information_schema数据库

use information_schema;

查询mysql使用空间

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;

查询所有数据库占用磁盘空间大小 


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;

查询某个库所使用的磁盘空间大小 

 

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='某个库';

查询某个库下表使用空间

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;

 查看指定数据库的某个表的大小

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='某个库' and table_name='某个表';

你可能感兴趣的:(数据库,sql,mysql,数据库,后端,开发语言)