views:

73

answers:

3

Hello. I want to know the size of my database using php. How to display the size in megabytes entire database? Size in megabytes a specific request?

A: 

Try querying information_schema.

Svisstack
+1  A: 

Try this to get the size in bytes:

mysql_select_db("yourdatabase");  
$q = mysql_query("SHOW TABLE STATUS");  
$size = 0;  
while($row = mysql_fetch_array($q)) {  
    $size += $row["Data_length"] + $row["Index_length"];  
}

then to convert in megabytes:

$decimals = 2;  
$mbytes = number_format($size/(1024*1024),$decimals);
Brainfeeder
+1  A: 
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
GROUP BY table_schema ;
eldar