MySQL: Get database and table sizes

Get the size in GB of each database in mysql.
[code language=”sql”]
SELECT
table_schema AS "Database Name",
sum( data_length + index_length ) / 1024 / 1024 / 1024 AS "Database Size in GB",
sum( data_free )/ 1024 / 1024 / 1024 AS "Free Space in GB"
FROM information_schema.TABLES
GROUP BY table_schema;
[/code]

Get database status in mysql.
[code language=”sql”]
SHOW TABLE STATUS FROM my_finance;
[/code]

Get all table sizes of a database schema in mysql.
[code language=”sql”]
SELECT TABLE_NAME AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 2) AS "Table size in MB"
FROM information_schema.TABLES
WHERE table_schema = "my_finance"
ORDER BY (data_length + index_length) DESC;
[/code]

Search within Codexpedia

Custom Search

Search the entire web

Custom Search