在Windows(Wamp)上使用mysql 5.5.2,我正在编写一个使用多个数据库的Java应用程序。我想列出数据库名称及其创建日期。数据库具有同一表的唯一数据变化(存档)。Java有什么技巧吗?
编辑:
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| information_schema |
| formaction_archive_test |
| mysql |
| performance_schema |
| sw_formaction |
| test |
+-------------------------+
6 rows in set (0.00 sec)
"formaction_archive_test"和"sw_formaction"都是由我"根"创建的,它们具有相同的表。我的问题是如何获得它们各自的创建日期。
我找到了这个解决方案:
mysql> use information_schema;
Database changed
mysql> SELECT table_name, create_time
-> FROM tables
-> WHERE table_schema NOT IN('mysql', 'information_schema') ;
+----------------------------------------------+---------------------+
| table_name | create_time |
+----------------------------------------------+---------------------+
| cond_instances | NULL |
| events_waits_current | NULL |
| events_waits_history | NULL |
| events_waits_history_long | NULL |
| events_waits_summary_by_instance | NULL |
| events_waits_summary_by_thread_by_event_name | NULL |
| events_waits_summary_global_by_event_name | NULL |
| file_instances | NULL |
| file_summary_by_event_name | NULL |
| file_summary_by_instance | NULL |
| mutex_instances | NULL |
| performance_timers | NULL |
| rwlock_instances | NULL |
| setup_consumers | NULL |
| setup_instruments | NULL |
| setup_timers | NULL |
| threads | NULL |
| annee | 2012-06-06 16:19:04 |
| categorie | 2012-06-06 16:19:04 |
| certification | 2012-06-06 16:19:04 |
| client | 2012-06-06 16:19:04 |
| clientold | 2012-06-06 16:19:04 |
| connaisance_ecole | 2012-06-06 16:19:04 |
| duree | 2012-06-06 16:19:04 |
| eleve | 2012-06-06 16:19:04 |
| famille | 2012-06-06 16:19:04 |
| formateur | 2012-06-06 16:19:04 |
| formation | 2012-06-06 16:19:04 |
| inscription | 2012-06-06 16:19:04 |
| lieux | 2012-06-06 16:19:05 |
| lst_formation | 2012-06-06 16:19:05 |
| moyen_paiement | 2012-06-06 16:19:05 |
| paiement | 2012-06-06 16:19:05 |
| session | 2012-06-06 16:19:05 |
| souhait | 2012-06-06 16:19:05 |
| souhaits | 2012-06-06 16:19:05 |
| type_certification | 2012-06-06 16:19:05 |
+----------------------------------------------+---------------------+
37 rows in set (0.01 sec)
但它只向我显示最后创建的数据库信息。可能是解决方案是查看文件创建日期?
应该是这个请求来获取它:
SELECT table_name, create_time
FROM information_schema.tables
您可以删除information_schema
并mysql
架构以获取您创建的架构:
SELECT table_name, create_time
FROM information_schema.tables
WHERE table_schema NOT IN('mysql', 'information_schema')
编辑:
要获取数据库创建时间,唯一的方法是检查最旧的表:
SELECT MIN(create_time)
FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'my_database'
如果需要,您可以在数据库中插入一个无用(或不无用)的表,例如 _config
,该表永远不会被删除。
我不确定 Java 中是否有特定的技巧可以提供帮助,但检查此处引用的INFORMATION_SCHEMA_TABLES
表:http://dev.mysql.com/doc/refman/5.0/en/tables-table.html 可能会有所帮助。 可能采用所有表的最短创建时间,并将其用作数据库创建时间?
AFAIK,没有办法检查何时使用纯SQL创建数据库。