How can I determine when an InnoDB table was last changed?

后端 未结 3 729
攒了一身酷
攒了一身酷 2020-12-10 13:52

I\'ve had success in the past storing the (heavily) processed results of a database query in memcached, using the last update time of the underlying tables(s) as part of the

相关标签:
3条回答
  • 2020-12-10 14:22

    If you're not really interested when the database was changed, but want to know wether or not one database table was changed you should look into MySQL CHECKSUM TABLE

    Hope this helps.

    0 讨论(0)
  • 2020-12-10 14:32

    I would suggest adding another column to the table and let MySQL keep track of when the table was last modified, something like this:

    ADD COLUMN `last_update` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
    
    0 讨论(0)
  • 2020-12-10 14:33

    This is MySQL bug 14374, 15438, and underlying InnoDB bug 2681.

    I have two suggestions (other than patching MySQL).

    1. If you're using one table per file (innodb_file_per_table), stat the underlying file. You could write a MySQL function/extension to do this. This may lag slightly, due to database caching.
    2. You can use after update, delete, and insert triggers to keep your own metadata table with the last update times for each table you're concerned with.

    I'd personally suggest the second, as its much more portable and doesn't depend on implementation details (such as innodb_file_per_table).

    0 讨论(0)
提交回复
热议问题