WEB开发 发表于 2013-1-1 22:13:32

快速统计某个数据库中每张表的数据量

<div id="cnblogs_post_body">在优化数据库的,或者在导入数据的时候,知道某个数据库中哪张数据表的数据量最多,有时候对我们还是有帮助的
所以自己简单写了几行代码用来实现以上需求
执行结果:
http://pic002.cnblogs.com/images/2012/350329/2012090117393340.png
<div class="cnblogs_code"><?php    $conn=mysql_connect('localhost','root','');    mysql_select_db('数据库',$conn);    $sql="SELECT information_schema.TABLES.TABLE_NAME FROM information_schema. TABLES WHERE    table_schema = '数据库'";    $res=mysql_query($sql);    while ($result = mysql_fetch_assoc($res)) {      $tables[]=$result['TABLE_NAME'];    };    echo "<table>            <tbody>            <tr>                <td>表名</td>                <td>数据量</td>            </tr>";    foreach ($tables as $k=>$v){      $sql_count="select count(id) AS nums,'".$v."' from ".$tables[$k];      $res_count=mysql_query($sql_count);      $result_count = mysql_fetch_assoc($res_count);      echo "<tr><td>".$result_count[$v].'</td><td>'.$result_count['nums'].'</td></tr>';    }    echo "</tbody></table>"?>
页: [1]
查看完整版本: 快速统计某个数据库中每张表的数据量