Content Error or Suggest an Edit
Notice a grammatical error or technical inaccuracy? Let us know; we will give you credit!
Getting Single MySQL Database Size
This is the command I use to get a single database size in MySQL: replace <DATABASE_NAME> with the database you wish to check.
mysql -e "SELECT table_schema AS \"Database\", ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS \"Size (MB)\" FROM information_schema.TABLES WHERE table_schema = \"<DATABASE_NAME>\" GROUP BY table_schema;"
Getting Entire Server MySQL Database Size
The following command will provide you with a list of databases and their sizes as well as a total.
mysql -e " SELECT * FROM ( SELECT table_schema AS 'Database', ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)' FROM information_schema.TABLES GROUP BY table_schema ) AS original_query UNION ALL SELECT 'Total' AS 'Database', ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)' FROM information_schema.TABLES ORDER BY CASE WHEN 'Database' = 'Total' THEN 1 ELSE 0 END, 'Size (MB)' DESC; "