MySQL: How can I get the timestamp of the last insertion to the database

限于喜欢 提交于 2019-12-01 21:33:05

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;

Just use this SQL: SHOW TABLE STATUS; and check Update_time column.

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.

This is basically what logging is all about.

On the CLI

  1. execute SET GLOBAL log_output = 'TABLE';
  2. 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!