如何获取 mysql 数据库表上次更新的确切日期和时间


How to get the exact date and time when mysql database table last updated?

大家好,我是 Web 开发的新手,我在获取 mysql 数据库表上次更新的日期和时间时遇到了问题,因为我必须在我的网页上显示它。我正确获得了上次更新日期,但时间不正确,请帮助我。

 <?php
    $sql = "SHOW TABLE STATUS FROM MydatabaseName LIKE 'TableName'";
    $tableStatus = mysql_query($sql);
while ($array = mysql_fetch_array($tableStatus)) {
          $updatetime = $array['Update_time'];
          $datetime = new DateTime($updatetime);
          echo $updatetime ;
     }
 ?>

如果这可以帮助你

SELECT UPDATE_TIME
FROM   information_schema.tables
WHERE  TABLE_SCHEMA = 'dbname'
AND TABLE_NAME = 'tabname'

如何知道 MySQL 表上次更新的时间?

因为你已经在MySQL中标记了一个问题。

你试过这个吗?看看这是否有帮助。

select columns from table order by date_time column desc limit 1:

如果你有一个相对较新版本的MySQL,你可以查询information_schema.tables

 select substr(update_time,1,10) as date_updated,
        substr(update_time,12) as time_updated 
 from information_schema.tables
 where 
 table_schema = 'name_of_your_database' and 
 table_name = 'your_table_name';

请注意,如果您的MySQL引擎是InnoDB,则这可能不适用于用户定义的表。它的工作原理就像MyISAM安装上宣传的那样。