查询mysql 库和表占的大小

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

解释如下:

在mysql中有一个默认的数据库 库名为`information_schema`,information_schema这张数据库保存了MySQL服务器所有数据库的信息。
 

use information_schema;   调用mysql自己的库分析,这个不改

1 查询整个库的情况

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;        什么都不改  直接执行

2 查询某个库的情况

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='库名';   修改成自己的库名

3 查询某个库下某个表情况

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='库名' and table_name='表名';     修改成自己的库名 表名

原文地址:https://www.cnblogs.com/fangyuandoit/p/13713816.html