Check MySQL database size
How to check MySQL database size in your server?
Actually MySQL already provide the information, what you need to do is just do a simple query to retrieve the data.
Below is the query :
View Code MYSQL
SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB", sum( data_free )/ 1024 / 1024 "Free Space in MB" FROM information_schema.TABLES WHERE table_schema = '<DATABASE NAME>' GROUP BY table_schema ; |
6 Comments to “Check MySQL database size”
Leave a Reply
Thanks dude, I’ve been locking for this one for a while. I’m impressed that everyone’s recommendation to know the size of a MySQL DB is “Install phpmyadmin and…”
Now, I get the results just fine, except for the Free Space, that one is allways zero. Do you know what that could mean?
I trying this gives me the error:
1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),…) with no GROUP columns is illegal if there is no GROUP BY clause
Hi nione,
Thanks for your comments…
I had amend the GROUP BY command in the query.
It should be work now.
Thanks mate, great help…
— Anish Sneh
Just used this and it doesn’t seem to report free space correctly. When I look in the actual information_schema.TABLES table I see that all the tables report the same amount of free space, which is presumably the free space on disk (or whatever mysql thinks is available to it?) Summing the data_free entries would seem to over-report the free space by counting it multiple times. I suppose this could be dependent on MySQL version/platform/storage type; I’m not sure.
Maybe just do “max( data_free )” rather than “sum( data_free )”?
hello, how can i used this query please?
thank you for your time