Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 645
Isis Avatar asked Oct 27 '10 11:10

Isis


1 Answers

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);
like image 114
ySgPjx Avatar answered Sep 25 '22 21:09

ySgPjx