How to get the size of the databases and tables in MySQL

Sizes of the databases

# mysql -uroot -p

SELECT table_schema "Data Base Name",
    sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
    sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema; 

Sizes of the tables in _DB_ database

# mysql -uroot -p

SELECT table_name AS "Table", 
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" 
FROM information_schema.TABLES 
WHERE table_schema = "_DB_";
comments powered by Disqus