How can I get size of table in my MySQL DB ?
Printable View
How can I get size of table in my MySQL DB ?
Here's a function I wrote awhile ago to get all the tables from a database, plus their number of rows and size:
Code:function gettableinfo($tdb) { '$tdb is the database
$sql_result = "SHOW TABLE STATUS FROM " .$tdb;
$result = mysql_query($sql_result);
if($result) {
$size = 0;
$stuff = '<table cellpadding="2" cellspacing="0" style="border: 1px solid #000000; width: 250px;">
<tr>
<td style="border-bottom: 1px solid #000000; padding-left: 4px; padding-right: 4px;"><b>Table Name</b></td>
<td style="border-bottom: 1px solid #000000; padding-left: 4px; padding-right: 4px;"><b>Records</b></td>
<td style="border-bottom: 1px solid #000000; padding-left: 4px; padding-right: 4px;"><b>Size</b></td>
</tr>';
while ($data = mysql_fetch_array($result)) {
$size = $data["Data_length"] + $data["Index_length"];
$stuff .= '<tr>
<td style="padding-left: 4px; padding-right: 4px;">' . $data['Name'] . '</td>
<td style="padding-left: 4px; padding-right: 4px;">' . $data['Rows'] . '</td>
<td align="right" style="padding-left: 4px; padding-right: 4px;">' . formatsize($size) . '</td>
</tr>';
}
$stuff .= '</table>';
return $stuff;
}
}
Thanks