mysql table size

查看数据库和表大小

1
2
3
4
5
6
7
8
9
10
11
12
13
mysql> use information_schema;

//要查询表所占的容量,就是把表的数据和索引加起来就可以了
mysql> select sum(DATA_LENGTH)+sum(INDEX_LENGTH) from information_schema.tables;

//查询所有的数据大小
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from tables;

//查询某个表的数据
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from tables where table_schema='pmsmonitorlog' AND table_name='$i';

//查询数据库大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home';