Skip to content

Instantly share code, notes, and snippets.

@efenacigiray
Last active November 28, 2019 13:21
Show Gist options
  • Save efenacigiray/e9c9e1318373e298071baa96d8564ac5 to your computer and use it in GitHub Desktop.
Save efenacigiray/e9c9e1318373e298071baa96d8564ac5 to your computer and use it in GitHub Desktop.
Database Size Estimation Queries
-- Display size of all databases in a MySQL server
SELECT table_schema AS 'Database Name',
sum(data_length + index_length) AS 'Size in Bytes',
round((sum(data_length + index_length) / 1024 / 1024), 4) AS 'Size in MB'
FROM information_schema.TABLES
WHERE table_schema NOT IN ('information_schema',
'performance_schema',
'mysql',
'sys')
GROUP BY table_schema
ORDER BY sum(data_length + index_length) DESC;
-- Display size of tables in a database
SELECT TABLE_NAME,
table_rows,
data_length,
index_length,
round(((data_length + index_length) / 1024 / 1024),2) "Size"
FROM information_schema.TABLES
WHERE table_schema = "discus";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment