Database size of MySQL

Database size of MySQL


SELECT 
    s.schema_name,
    CONCAT(IFNULL(ROUND((SUM(t.data_length) + SUM(t.index_length)) / 1024 / 1024,
                            2),
                    0.00),
            'Mb') total_size,
    CONCAT(IFNULL(ROUND(((SUM(t.data_length) + SUM(t.index_length)) - SUM(t.data_free)) / 1024 / 1024,
                            2),
                    0.00),
            'Mb') data_used,
    CONCAT(IFNULL(ROUND(SUM(data_free) / 1024 / 1024, 2),
                    0.00),
            'Mb') data_free,
    IFNULL(ROUND((((SUM(t.data_length) + SUM(t.index_length)) - SUM(t.data_free)) / ((SUM(t.data_length) + SUM(t.index_length))) * 100),
                    2),
            0) pct_used
FROM
    INFORMATION_SCHEMA.SCHEMATA s,
    INFORMATION_SCHEMA.TABLES t
WHERE
    s.schema_name = t.table_schema
        AND s.schema_name LIKE 'rp%'
GROUP BY s.schema_name
ORDER BY total_size DESC;



Post a Comment

And that's all there is to it!

If anyone has any other questions or requests for future How To posts, you can either ask them in the comments or email me. Please don't feel shy at all!

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

Previous Post Next Post