I need to find out how much disk space my MySQL database is using. Let’s say I have a database called “inventory_system” and I want to know its total size.
I’ve been looking for a way to get this information but I’m not sure what’s the most reliable method. Should I use some SQL query or is there a better approach? I want to make sure I get accurate results that show the actual space being used by all the tables and data in that specific database.
Any suggestions on how to accomplish this would be really helpful. Thanks!
To determine the size of your MySQL database, you can execute a query on the information_schema. Use the following SQL command:
SELECT
table_schema AS 'Database',
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size in MB'
FROM information_schema.tables
WHERE table_schema = 'inventory_system'
GROUP BY table_schema;
This query calculates the combined size of both data and index, providing an accurate representation of the space utilized by your database. Ensure you have the necessary permissions to access the information_schema.
quick tip: run SHOW TABLE STATUS FROM inventory_system; to get data_length and index_length for each table. you’ll need to add them up yourself, but it’s great for spotting which tables are hogging the most space.