獲取 MySQL 資料庫上次更改的日期/時間?
你可以利用 INFORMATION_SCHEMA.TABLES 獲取 MySQL 資料庫上次更改的日期/時間。語法如下 −
SELECT update_time FROM information_schema.tables WHERE table_schema = 'yourDatabaseName’' AND table_name = 'yourTableName’;
為了理解上述語法,我們建立一個表。建立表的查詢如下 −
mysql> create table TblUpdate -> ( -> Id int not null auto_increment primary key, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.49 sec)
使用 insert 命令在表中插入一些記錄。查詢如下 −
mysql> insert into TblUpdate(Name) values('John'); Query OK, 1 row affected (0.18 sec) mysql> insert into TblUpdate(Name) values('Carol'); Query OK, 1 row affected (0.22 sec)
現在,你可以使用 select 語句顯示錶中的所有記錄。查詢如下 −
mysql> select *from TblUpdate;
輸出
+----+-------+ | Id | Name | +----+-------+ | 1 | John | | 2 | Carol | +----+-------+ 2 rows in set (0.00 sec)
現在,你可以使用以下查詢更新表 −
mysql> update TblUpdate set Name = 'James' where Id=2; Query OK, 1 row affected (0.15 sec) Rows matched: 1 Changed: 1 Warnings: 0
因此,我們剛剛更新了上面的表。現在使用以下查詢獲取 MySQL 資料庫上次更改的日期/時間 −
mysql> SELECT update_time -> FROM information_schema.tables -> WHERE table_schema = 'sample' -> AND table_name = 'TblUpdate' -> ;
以下輸出顯示我們於 2019-02-09 22:49:44 更新了資料庫 −
+---------------------+ | UPDATE_TIME | +---------------------+ | 2019-02-09 22:49:44 | +---------------------+ 1 row in set (0.89 sec)
廣告