user690182
user690182

Reputation: 279

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

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?

Upvotes: 6

Views: 14176

Answers (3)

ViES
ViES

Reputation: 371

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

Upvotes: 8

Starx
Starx

Reputation: 78981

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.

Upvotes: 0

Kory Sharp
Kory Sharp

Reputation: 490

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.

Upvotes: 0

Related Questions