要获取上次访问时间,请尝试以下语法 -
select update_timefrom information_schema.tableswhere table_schema = 'yourdatabasename'and table_name = 'yourtablename'
上面的语法给出了有关 myisam 引擎类型的最后访问信息。
这里,我们的数据库是“business”,我们将使用名为“twoprimarykeytabledemo”的表。
要获取 mysql 数据库的上次访问时间,请使用以下查询。
情况 1 - 查询如下 -
mysql> select update_time -> from information_schema.tables -> where table_schema = 'business' -> and table_name = 'twoprimarykeytabledemo';
输出如下 -
+---------------------+| update_time |+---------------------+| 2018-11-21 16:51:50 |+---------------------+1 row in set (0.24 sec)
案例 2 -
mysql> select update_time -> from information_schema.tables -> where table_schema = 'business' -> and table_name = 'currenttimezone';
输出如下 -
+---------------------+| update_time |+---------------------+| 2018-10-29 17:20:18 |+---------------------+1 row in set (0.20 sec)
情况3 - 如果您的表引擎类型是innodb,那么您将得到null。
查询如下 -
mysql> select update_time -> from information_schema.tables -> where table_schema = 'business' -> and table_name = 'zerofilldemo';
以下是输出 -
+-------------+| update_time |+-------------+| null |+-------------+1 row in set (0.09 sec)
以上就是如何获取 mysql 数据库的最后访问(和/或写入)时间?的详细内容。