Home > Database > Mysql Tutorial > body text

How to get the last access (and/or write) time of a MySQL database?

WBOY
Release: 2023-09-11 13:29:02
forward
1168 people have browsed it

如何获取 MySQL 数据库的最后访问(和/或写入)时间?

To get the last access time, try the following syntax -

SELECT update_time
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = 'yourDatabaseName'
AND table_name = 'yourTableName'
Copy after login

The above syntax gives the last access information about the MyISAM engine type.

Here, our database is "business" and we will use a table named "twoprimarykeytabledemo".

< p>To get the last access time of a MySQL database, use the following query.

Case 1 - The query is as follows-

mysql> SELECT update_time
   -> FROM INFORMATION_SCHEMA.TABLES
   -> WHERE table_schema = &#39;business&#39;
   -> AND table_name = &#39;twoprimarykeytabledemo&#39;;
Copy after login

The output is as follows-

+---------------------+
| UPDATE_TIME         |
+---------------------+
| 2018-11-21 16:51:50 |
+---------------------+
1 row in set (0.24 sec)
Copy after login

Case 2 -

mysql> SELECT update_time
   -> FROM INFORMATION_SCHEMA.TABLES
   -> WHERE table_schema = &#39;business&#39;
   -> AND table_name = &#39;currenttimezone&#39;;
Copy after login

The output is as follows -

+---------------------+
| UPDATE_TIME         |
+---------------------+
| 2018-10-29 17:20:18 |
+---------------------+
1 row in set (0.20 sec)
Copy after login

Case 3 - If your table engine type is InnoDB, then you will get NULL.

The query is as follows -

mysql> SELECT update_time
   -> FROM INFORMATION_SCHEMA.TABLES
   -> WHERE table_schema = &#39;business&#39;
   -> AND table_name = &#39;zerofilldemo&#39;;
Copy after login

The following is the output -

+-------------+
| UPDATE_TIME |
+-------------+
| NULL        |
+-------------+
1 row in set (0.09 sec)
Copy after login

The above is the detailed content of How to get the last access (and/or write) time of a MySQL database?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!