Code solutions to PHP, JS, CSSCode source PHP, JS, CSS

Spread your code soluces to the world

Love me
Solucior » MYSQL » MySQL table statistics

MySQL table statistics

06/03/2011 by Dux   -   5/5 (2 ratings)

This little script displays the usage statistics of your MySQL tables using SHOW TABLE STATUS syntax


Rows	                20
Data size 0.034 MB
Index size 0.002 MB
Total size 0.035 MB
Lost space 0 MB
Avg row size 1.72 KB
Last modified 2011-06-03 17:43:01

source code

// Connect to MySQL DBase
// ...

$res = mysql_query("SHOW TABLE STATUS FROM your_base LIKE 'your_table'");
$stats = mysql_fetch_array($res);

<tr><td>Rows</td>              <td>'
<tr><td>Data size</td>         <td>'
.round($stats['Data_length']/1024/1024, 3).' MB</td></tr>
<tr><td>Index size</td>        <td>'
.round($stats['Index_length']/1024/1024, 3).' MB</td></tr>
<tr><td><b>Total size</b></td> <td><b>'
.round($stats['Index_length']/1024/1024 + $stats['Data_length']/1024/1024, 3).' MB</b></td></tr>
<tr><td>Lost space</td>        <td>'
.round($stats['Data_free']/1024/1024, 3).' MB</td></tr>
<tr><td>Avg row size</td>      <td>'
.round($stats['Avg_row_length']/1024, 2).' KB</td></tr>
<tr><td>Last modified</td>     <td>'

Rate this code     |     Copied : 78x

Comments for MySQL table statistics

No comment
Add a comment Nickname   Site

MySQL table statistics
Automatic search result page
Simple function for PHP syntax highlighting
Dynamically add rows to a form. Complete solution
Simple method : listing files from a directory
Close HTML tags function