Search code examples
phpmysqldatabasesize

Size of database . PHP - MySQL


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?


Solution

  • 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);