MySQL 查询查找最近一小时内修改的表?

WBOY
发布: 2023-09-14 19:05:04
转载
1122 人浏览过

MySQL 查询查找最近一小时内修改的表?

您可以借助 INFORMATION_SCHEMA.TABLES 来实现此目的。使用带间隔的 date_sub() 。语法如下 -

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE DATE_SUB(NOW(), INTERVAL -1HOUR) < &lsquo;UPDATE_TIME&rsquo;;
登录后复制

现在您可以检查上面的语法。这是查找过去一小时内修改的表的查询 -

mysql> select table_name from `INFORMATION_SCHEMA`.`TABLES`
-> WHERE
-> DATE_SUB(NOW(), INTERVAL 1 HOUR) < `UPDATE_TIME`;
登录后复制

输出

+---------------------+
| TABLE_NAME          |
+---------------------+
| innodb_table_stats  |
| innodb_index_stats  |
| employeeinformation |
+---------------------+
3 rows in set (0.37 sec)
登录后复制

以上查询仅选择表名。如果您想要表架构、表类型等信息,则需要使用以下查询。查询显示最近一小时内修改的表 -

mysql> SELECT *
-> FROM `INFORMATION_SCHEMA`.`TABLES`
-> WHERE
-> DATE_SUB(NOW(), INTERVAL 1 HOUR) < `UPDATE_TIME`;
登录后复制

以下是显示最近一小时内修改的表信息的输出 -

+---------------+--------------+---------------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+---------------------------------------+---------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME         | TABLE_TYPE  | ENGINE | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME | UPDATE_TIME | CHECK_TIME | TABLE_COLLATION | CHECKSUM | CREATE_OPTIONS | TABLE_COMMENT |
+---------------+--------------+---------------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+---------------------------------------+---------------+
| def           | mysql        | innodb_table_stats  | BASE TABLE | InnoDB | 10      | Dynamic    | 449        | 145            | 65536       | 0               | 0            | 4194304   | NULL | 2018-09-22 20:37:26 | 2018-12-24 15:13:41 | NULL | utf8_bin | NULL |
row_format=DYNAMIC stats_persistent=0 | |
| def           | mysql        | innodb_index_stats  | BASE TABLE | InnoDB | 10      | Dynamic    | 1413       | 243            | 344064      | 0               | 0            | 4194304   | NULL | 2018-09-22 20:37:26 | 2018-12-24 15:13:41 | NULL | utf8_bin | NULL |
row_format=DYNAMIC stats_persistent=0 | |
| def           | test         | employeeinformation | BASE TABLE | InnoDB | 10      | Dynamic    | 6          | 2730           | 16384       | 0               | 0            | 0         | NULL | 2018-12-24 15:12:04 | 2018-12-24 15:14:00 | NULL | utf8mb4_0900_ai_ci | NULL | |
|
+---------------+--------------+---------------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+---------------------------------------+---------------+
3 rows in set (43.72 sec)
登录后复制

以上是MySQL 查询查找最近一小时内修改的表?的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:tutorialspoint.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板