How can I tell when a MySQL table was last updated?

后端 未结 16 1792
忘了有多久
忘了有多久 2020-11-22 17:17

In the footer of my page, I would like to add something like \"last updated the xx/xx/200x\" with this date being the last time a certain mySQL table has been updated.

16条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 17:56

    a) It will show you all tables and there last update dates

    SHOW TABLE STATUS FROM db_name;
    

    then, you can further ask for specific table:

    SHOW TABLE STATUS FROM db_name like 'table_name';
    

    b) As in above examples you cannot use sorting on 'Update_time' but using SELECT you can:

    SELECT * FROM information_schema.tables WHERE TABLE_SCHEMA='db_name' ORDER BY UPDATE_TIME DESC;
    

    to further ask about particular table:

    SELECT * FROM information_schema.tables WHERE TABLE_SCHEMA='db_name' AND table_name='table_name' ORDER BY UPDATE_TIME DESC';
    

提交回复
热议问题