我有一个包含约 20 个表的数据库。每个表都有一个“dtLogTime”列,用于记录插入该行的时间。我想弄清楚每个表每天记录的大小(可能是 kb 或 mb)。更具体地说,我只对最近 3 天感兴趣。此外,这些表会跟踪特定时间间隔内的数据(即 2 周、1 个月等),这意味着我每存储新的一天数据就会丢失一天的数据。
我发现这段代码可以显示每个表的大小。
<?php
$link = mysql_connect('host', 'username', 'password');
$db_name = "your database name here";
$tables = array();
mysql_select_db($db_name, $link);
$result = mysql_query("SHOW TABLE STATUS");
while($row = mysql_fetch_array($result)) {
/* We return the size in Kilobytes */
$total_size = ($row[ "Data_length" ] +
$row[ "Index_length" ]) / 1024;
$tables[$row['Name']] = sprintf("%.2f", $total_size);
}
print_r($tables);
?>
当我尝试做的时候
"SHOW TABLE STATUS WHERE dtLogTime < '2011-08-28 00:00:00'
AND dtLogTime >= '2011-08-27 00:00:00'"
它给了我一个错误。有办法做到这一点吗?
谢谢
最佳答案
您需要包含一个LIKE
子句来指定表。来源:http://dev.mysql.com/doc/refman/5.6/en/show-table-status.html
SHOW TABLE STATUS
LIKE YourTable
WHERE dtLogTime < '2011-08-28 00:00:00'
AND dtLogTime >= '2011-08-27 00:00:00'
关于php - 如何获取表格每天的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7237251/