MySQL: how can I get the timestamp of the last insert into the database?

How can I check when was the last time (timestamp) I wrote in the database, regardless of the database table I inserted into?

+3


source to share


4 answers


Disabled so as not to be the answer (cannot be deleted as is customary). See the comments below this answer.

I was unable to use information_schema.tables update_time

as the column was not updating, but create_time

it worked for that. It will work for update_time

(if changed) if update_time

updated, which may 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;

      

-1


source


Just use this SQL: SHOW TABLE STATUS;

and check the Update_time column .



+3


source


Add the field for the modified date to the table and use LAST_INSERT_ID () to determine the last row (if you do it right away). Otherwise, just get the most recent date from the changed field for the table.

0


source


This is basically what logging is .

In the CLI

  • execute SET GLOBAL log_output = 'TABLE';

  • execute SET GLOBAL general_log = 'ON';

Now the table general_log

inside mysql

will register all such actions in the database. Use phpMyadmin or similar to view them. You can query their results very efficiently.

0


source







All Articles