How to calculate the MySQL database size
As i know, there are two ways to calculate MySQL database size.
1. SQL script
Sum up the data_length + index_length is equal to the total table size.
- data_length – store the real data.
- index_length – store the table index.
Here’s the SQL script to list out the entire databases size
SELECT table_schema "Data Base Name", SUM( data_length + index_length) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema ;
Another SQL script to list out one database size, and each tables size in detail
SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "schema_name";
2. Locate the MySQL stored data
Access this article to find out where does MySQL database saved the data.
Windows
Locate the MySQL ibdata1 file, right click on the file and click the properties, see the size? :)
Linux
Locate the MySQL ibdata1 file
mkyong@myserver:/var/lib/mysql$ ls -lh total 1.5G drwx------ 2 mysql mysql 4.0K 2009-08-26 13:36 mydatabase -rw-r--r-- 1 root root 0 2009-08-19 09:39 debian-5.0.flag -rw-rw---- 1 mysql mysql 1.5G 2009-08-27 17:32 ibdata1 -rw-rw---- 1 mysql mysql 5.0M 2009-08-27 17:32 ib_logfile0 -rw-rw---- 1 mysql mysql 5.0M 2009-08-27 17:32 ib_logfile1 drwxr-xr-x 2 mysql root 4.0K 2009-08-19 11:19 mysql -rw------- 1 root root 6 2009-08-19 09:39 mysql_upgrade_info






[...] için t?klay?n?z. Bu yaz? MySQL kategorisine Can Yapan taraf?ndan yaz?lm??t?r. yer imlerinize [...]
Nice, just what I was looking for. It’s obvious from your post, but just for completeness, the query to get the total size of a particular DB:
Thanks!.
Thanks for your extra input.
[...] Thanks to Mkyong’s blog post who provided the SQL statements for analysing the database and tables. And of course [...]
Your select statements for displaying table- and database-sizes are great. Exactly what I was looking for.
Thanks,
Bernd
[...] in http://www.mkyong.com/mysql/how-to-calculate-the-mysql-database-size/ GA_googleAddAttr("AdOpt", "1"); GA_googleAddAttr("Origin", "other"); [...]
A simple trick with 1 line total;
Just sum up all of the files in the database path
this way you get a true measure of the HD storage.
ls /var/lib/mysql/ -lh|grep total
Total 21M
Hi Mickey, thank for your tip :)
I want to calculate real data size per row of table not table
May i know why you need calculate per row? row data may vary in different row. Please share your answer if you manage to find it out.
ibdata1 is the sum of all databases that you have on the installation and that can be more than one database.
thanks for the information, then the script version will be more accurate at the calculation of the MySQL database size