问题
How can I check when was the last time (timestamp) that I wrote in the database, irrespectively of the database table that I inserted into?
回答1:
Turned out to not be the answer (can't delete as accepted). See comments below this answer.
I wasn't able to use information_schema.tables update_time
as the column wasn't being updated but for create_time
this worked. It would work for update_time
(if changed) if update_time
gets updated which might be true in your setup.
select table_schema,table_name,max_time from information_schema.tables t1 JOIN
(select MAX(t2.create_time) AS max_time FROM
information_schema.tables t2 where
table_schema ='test') as t3
on t1.create_time = t3.max_time;
回答2:
Just use this SQL: SHOW TABLE STATUS;
and check Update_time column.
回答3:
Add a field for modified date in the table and use LAST_INSERT_ID() to determine the last row (if you're doing it right away). Otherwise just retrieve the most recent date from the modified field for the table.
回答4:
This is basically what logging is all about.
On the CLI
- execute
SET GLOBAL log_output = 'TABLE';
- execute
SET GLOBAL general_log = 'ON';
Now, a table general_log
inside mysql
database will log all such actions on database.
Use phpMyadmin or similar to view these. You can query from their results very effectively.
来源:https://stackoverflow.com/questions/9657206/mysql-how-can-i-get-the-timestamp-of-the-last-insertion-to-the-database