Get MySQL database and table size

You can get size of the MySQL databases as following.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
SELECT table_schema AS "Database Name",
Round(Sum(data_length + index_length) / 1024 / 1024, 1) AS "Size in MB"
FROM information_schema.tables
GROUP BY table_schema;
SELECT table_schema AS "Database Name", Round(Sum(data_length + index_length) / 1024 / 1024, 1) AS "Size in MB" FROM information_schema.tables GROUP BY table_schema;
SELECT table_schema AS "Database Name", 
   Round(Sum(data_length + index_length) / 1024 / 1024, 1) AS "Size in MB"
FROM   information_schema.tables 
GROUP  BY table_schema;

And get size of tables.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
SELECT TABLE_NAME AS "Table Name",
table_rows AS "Quant of Rows",
ROUND( (data_length + index_length) /1024, 2 ) AS "Size Kb"
FROM information_schema.TABLES
WHERE information_schema.TABLES.table_schema = 'DATABASE NAME HERE'
SELECT TABLE_NAME AS "Table Name", table_rows AS "Quant of Rows", ROUND( (data_length + index_length) /1024, 2 ) AS "Size Kb" FROM information_schema.TABLES WHERE information_schema.TABLES.table_schema = 'DATABASE NAME HERE'
SELECT TABLE_NAME AS "Table Name", 
   table_rows AS "Quant of Rows", 
   ROUND( (data_length + index_length) /1024, 2 ) AS "Size Kb"
FROM   information_schema.TABLES
WHERE   information_schema.TABLES.table_schema = 'DATABASE NAME HERE'

Published by Man Friday

Application Developer, Photographer and WordPress aficionado. Particularly interested in relational database design, In usability, UX and accessibility on software development. I just wear glasses, Lives in Ubonratchathani, Thailand.