개발/Database

MySQL table 용량 확인

내가지니 2012. 5. 17. 22:21

DB를 사용하다 보면 table별 용량 확인이 필요할 때가 있다.

mysql에서 meta정보를 확인하기 위해서는 information_schema를 이용하면 된다.

이번 포스트에서는 table용량 확인을 위한 sql을 정리하기로 하자....



[DB 용량확인]

SELECT table_schema "Database Name", 

            SUM(data_length + index_length) / 1024 / 1024 "Size(MB)" 

FROM information_schema.TABLES 

GROUP BY table_schema;


[table 용량확인]

SELECT 

    concat(table_schema,'.',table_name),   

    concat(round(table_rows/1000000,2),'M') rows,   

    concat(round(data_length/(1024*1024*1024),2),'G') DATA,   

    concat(round(index_length/(1024*1024*1024),2),'G') idx,   

    concat(round((data_length+index_length)/(1024*1024*1024),2),'G') total_size,   

    round(index_length/data_length,2) idxfrac    

FROM information_schema.TABLES  

    where table_name = '테이블명'  ;



[출처] [MySQL] database table용량 확인|작성자 juner84