要获取MySQL表的创建日期,请使用information_schema。语法如下-
SELECT create_time FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'yourDatabaseName’ AND table_name = 'yourTableName';
对您的数据库和表名应用以上语法。在这里,我正在使用数据库“ business”,表名是“ student”。查询如下-
SELECT create_time FROM INFORMATION_SCHEMA.TABLES -> WHERE table_schema = 'business' -> AND table_name = 'student';
以下是显示表创建时间的输出-
+---------------------+ | CREATE_TIME | +---------------------+ | 2018-10-01 12:26:57 | +---------------------+ 1 row in set (0.12 sec)
让我们来看另一个示例,并从头开始创建表。
create table DateAsStringDemo -> ( -> YourDateTime datetime -> );
我刚刚创建了一个表,我当前的日期时间如下-
select now();
以下是输出-
+---------------------+ | now() | +---------------------+ | 2018-11-26 18:12:29 | +---------------------+ 1 row in set (0.00 sec)
现在您可以检查上表的创建时间,该时间将给出日期2018-11-26。
查询如下-
SELECT create_time FROM INFORMATION_SCHEMA.TABLES -> WHERE table_schema = 'test' -> AND table_name = 'DateAsStringDemo';
以下是输出-
+---------------------+ | CREATE_TIME | +---------------------+ | 2018-11-26 18:01:44 | +---------------------+ 1 row in set (0.00 sec)