MySQL에서 Table 용량 확인하는 방법

IT정보 2022. 5. 23. 10:23
728x90
반응형

구글링 통해서 확인한 SQL 쿼리인데 실행이 안 되어서 수정했습니다.

SELECT
    table_name AS 'TableName',
    ROUND(SUM(data_length + index_length) /(1024 * 1024), 2) AS 'All(MB)',
    ROUND(data_length /(1024 * 1024), 2) AS 'Data(MB)',
    ROUND(index_length /(1024 * 1024), 2) AS 'Index(MB)'
FROM
    information_schema.tables
GROUP BY
    table_name,
    data_length,
    index_length
ORDER BY
    data_length DESC;

특정 DB 스키마(XXXXX)의 테이블만 보고 싶을 경우에는 아래와 같이 하시면 됩니다.

SELECT
    table_name AS 'TableName',
    ROUND(SUM(data_length + index_length) /(1024 * 1024), 2) AS 'All(MB)',
    ROUND(data_length /(1024 * 1024), 2) AS 'Data(MB)',
    ROUND(index_length /(1024 * 1024), 2) AS 'Index(MB)'
FROM
    information_schema.tables
WHERE
    table_schema = 'XXXXX'
GROUP BY
    table_name,
    data_length,
    index_length
ORDER BY
    data_length DESC;

728x90
반응형