MySQL 查詢尋找最近一小時內修改的表格?

WBOY
發布: 2023-09-14 19:05:04
轉載
1112 人瀏覽過

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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!