Indeed, its currently very hard to get proper sizes from MySQL.
After lots of research, i found the following reliable method:
Code:
SELECT s.schema_name, CONCAT(IFNULL(ROUND((SUM(t.data_length)+SUM(t.index_length))/1024/1024,2),0.00),"Mb") total_size, CONCAT(IFNULL(ROUND(((SUM(t.data_length)+SUM(t.index_length))-SUM(t.data_free))/1024/1024,2),0.00),"Mb") data_used, CONCAT(IFNULL(ROUND(SUM(data_free)/1024/1024,2),0.00),"Mb") data_free,IFNULL(ROUND((((SUM(t.data_length)+SUM(t.index_length))-SUM(t.data_free))/((SUM(t.data_length)+SUM(t.index_length)))*100),2),0) pct_used, COUNT(table_name) total_tables FROM INFORMATION_SCHEMA.SCHEMATA s LEFT JOIN INFORMATION_SCHEMA.TABLES t ON s.schema_name = t.table_schema WHERE s.schema_name = "mydatabasename" GROUP BY s.schema_name ORDER BY pct_used DESC;
Just change the "mydatabasename" to the name of the database you want to get data for, keep the double quotes around the name.
The above should print this:
Code:
+-------------+------------+-----------+-----------+----------+--------------+
| schema_name | total_size | data_used | data_free | pct_used | total_tables |
+-------------+------------+-----------+-----------+----------+--------------+
| mydb | 100.87Mb | 100.86Mb | 0.00Mb | 100.00 | 49 |
+-------------+------------+-----------+-----------+----------+--------------+
the "size" is the REQUESTED size (but not used by data)
the "used" is the ACTUAL data size used in the db
unfortunately, it doesn't work on MySQL 4.1 that i tried, it only works on my systems with MySQL 5.x.
maybe not the solution cPanel developers are looking for, but worth taking a look.