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

后端 未结 16 1673
忘了有多久
忘了有多久 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:46

    Just grab the file date modified from file system. In my language that is:

     tbl_updated = file.update_time(
            "C:\ProgramData\MySQL\MySQL Server 5.5\data\mydb\person.frm")
    

    Output:

    1/25/2013 06:04:10 AM
    
    0 讨论(0)
  • 2020-11-22 17:50

    Not sure if this would be of any interest. Using mysqlproxy in between mysql and clients, and making use of a lua script to update a key value in memcached according to interesting table changes UPDATE,DELETE,INSERT was the solution which I did quite recently. If the wrapper supported hooks or triggers in php, this could have been eaiser. None of the wrappers as of now does this.

    0 讨论(0)
  • 2020-11-22 17:52

    OS level analysis:

    Find where the DB is stored on disk:

    grep datadir /etc/my.cnf
    datadir=/var/lib/mysql
    

    Check for most recent modifications

    cd /var/lib/mysql/{db_name}
    ls -lrt
    

    Should work on all database types.

    0 讨论(0)
  • 2020-11-22 17:54

    For a list of recent table changes use this:

    SELECT UPDATE_TIME, TABLE_SCHEMA, TABLE_NAME
    FROM information_schema.tables
    ORDER BY UPDATE_TIME DESC, TABLE_SCHEMA, TABLE_NAME
    
    0 讨论(0)
  • 2020-11-22 17:54

    This is what I did, I hope it helps.

    <?php
        mysql_connect("localhost", "USER", "PASSWORD") or die(mysql_error());
        mysql_select_db("information_schema") or die(mysql_error());
        $query1 = "SELECT `UPDATE_TIME` FROM `TABLES` WHERE
            `TABLE_SCHEMA` LIKE 'DataBaseName' AND `TABLE_NAME` LIKE 'TableName'";
        $result1 = mysql_query($query1) or die(mysql_error());
        while($row = mysql_fetch_array($result1)) {
            echo "<strong>1r tr.: </strong>".$row['UPDATE_TIME'];
        }
    ?>
    
    0 讨论(0)
  • 2020-11-22 17:55

    I got this to work locally, but not on my shared host for my public website (rights issue I think).

    SELECT last_update FROM mysql.innodb_table_stats WHERE table_name = 'yourTblName';
    
    '2020-10-09 08:25:10'
    

    MySQL 5.7.20-log on Win 8.1

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