DBA
[MySQL] DB 용량 확인, 테이블별 용량 확인
엘리후
2024. 2. 26. 20:46
ㅁ 들어가면서
MySQL의 용량을 분석하기 위한 쿼리를 정리하였습니다.
update...
댓글의 질문 때문에 확인한 결과,
테이블이 뷰인 경유 용량과 건수는 null로 나타난다.
ㅁ 데이터베이스 용량 확인
SELECT
table_schema AS 'Database',
ROUND(SUM(data_length+index_length)/1024/1024, 1) AS 'Size(MB)'
FROM
information_schema.tables
WHERE
table_schema not in ('sys', 'mysql', 'information_schema', 'performance_schema')
GROUP BY table_schema
ORDER BY 2 DESC;

ㅁ 전체 용량 확인
SELECT
ROUND(SUM(data_length+index_length)/1024/1024, 1) AS 'Used(MB)',
ROUND(SUM(data_free)/1024/1024, 1) AS 'Free(MB)'
FROM
information_schema.tables;

ㅁ 테이블별 용량 확인
SELECT
table_schema AS 'DatabaseName',
table_name AS 'TableName',
ROUND(SUM(data_length+index_length)/(1024*1024), 2) AS 'All(MB)',
ROUND(SUM(data_length)/(1024*1024), 2) AS 'Data(MB)',
ROUND(SUM(index_length)/(1024*1024), 2) AS 'Index(MB)'
FROM
information_schema.tables
WHERE
TABLE_SCHEMA not in ('sys', 'mysql', 'information_schema', 'performance_schema')
GROUP BY table_schema, table_name
ORDER BY 3 DESC;

ㅇ 테이블 중에 current_dept_emp, dept_emp_latest_date은 뷰 테이블이기 때문에 null로 나타난다.
ㅁ 테이블별 Rows 확인
SELECT
table_schema AS 'DatabaseName',
TABLE_NAME,
TABLE_ROWS
FROM
information_schema.tables
WHERE
TABLE_SCHEMA not in ('sys', 'mysql', 'information_schema', 'performance_schema')
ORDER BY 3 DESC;

ㅇ 테이블 중에 current_dept_emp, dept_emp_latest_date은 뷰 테이블이기 때문에 null로 나타난다.