2010-10-27 17 views
5

Voglio conoscere la dimensione del mio database usando php. Come visualizzare la dimensione in megabyte dell'intero database? Dimensione in megabyte una richiesta specifica?Dimensione del database. PHP - MySQL

risposta

9

Prova questo per ottenere la dimensione in byte:

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"]; 
} 

poi convertire in megabyte:

$decimals = 2; 
$mbytes = number_format($size/(1024*1024),$decimals); 
+0

L'ho usato oggi. Grazie! – frustratedtech

0

Prova a eseguire query information_schema.

6
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 ; 
2

cerco di modificare da fonte internet per questo caso, basta provare per favore.

<?php 
mysql_connect("localhost","root","password here"); 
$namadb=''; //put db name here 

$sql="SELECT table_schema 'db_name', SUM(data_length + index_length)/1024/1024 'db_size_in_mb' FROM information_schema.TABLES WHERE table_schema='$namadb' GROUP BY table_schema ;"; 
$query=mysql_query($sql); 
$data=mysql_fetch_array($query); 
print $data['db_size_in_mb'];