Skip to content

Instantly share code, notes, and snippets.

@chris
Created November 11, 2009 00:30
Show Gist options
  • Select an option

  • Save chris/231439 to your computer and use it in GitHub Desktop.

Select an option

Save chris/231439 to your computer and use it in GitHub Desktop.
SQL to get the size of your database (data, indexes, totals)
-- SQL to calculate the size of your database (data, indexes, total).
-- Replace the "DATABASE_NAME in the 2nd to last line with the name of your DB
SELECT concat( table_schema, '.', table_name ) table_name,
concat( round( data_length / ( 1024 *1024 ) , 2 ) , 'M' ) data_length,
concat( round( index_length / ( 1024 *1024 ) , 2 ) , 'M' ) index_length,
concat( round( round( data_length + index_length ) / ( 1024 *1024 ) , 2 ) , 'M' ) total_size
FROM information_schema.TABLES
WHERE table_schema = 'DATABASE_NAME'
ORDER BY data_length DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment