program

[MySQL] DB 데이터 크기, 여유공간 확인

littlecarbb 2017. 2. 22. 14:57

SELECT table_schema "Database Name", 

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

FROM information_schema.TABLES 

GROUP BY table_schema;







---------------------------------------------------------------------------

Mysql database 를 사용함에 있어서 현재 사용되어지고 있는 DB 의 사용량과 Table 에 대한 사용량을 

알아보는 방법에 대해서 알려드립니다.

 

1. Database 사용량 확인

 

SELECT table_schema "Database Name", 
SUM(data_length + index_length) / 1024 / 1024 "Size(MB)" 
FROM information_schema.TABLES 
GROUP BY table_schema;

 

이와같이 해주시면 전체 데이터베이스의 사용양이 나타나게 되며,

만약, 특정한 Database 에대한 용량만 보고자 한다면 다음과 같이 WHERE 조건을 주시면 됩니다.

 

SELECT table_schema "Database Name", 
SUM(data_length + index_length) / 1024 / 1024 "Size(MB)" 
FROM information_schema.TABLES 
WHERE table_schema = 'yulwon_new'
GROUP BY table_schema;

 




-- data size (GB 단위)

select sum(data_length+index_length)/1024/1024/1024 from information_schema.tables; 


-- data free (GB 단위) 

select data_free/1024/1024/1024 from information_schema.tables 

where table_schema='데이터베이스명';