1. 程式人生 > >檢視mysql資料庫大小

檢視mysql資料庫大小

要想知道每個資料庫的大小的話,步驟如下:

1、進入information_schema 資料庫(存放了其他的資料庫的資訊)

use information_schema;

 

2、查詢所有資料的大小:

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

 

3、檢視指定資料庫的大小:

比如檢視資料庫home的大小

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

 

4、檢視指定資料庫的某個表的大小

比如檢視資料庫home中 members 表的大小

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home' and table_name='members';

 

mysql檢視當前所有的資料庫和索引大小

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;

 

mysql檢視當前某個資料庫和資料庫下所有的表的大小

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 = 'mysql'
group by table_name
order by data_length desc;