java - 用java获取Mysql数据库创建日期

标签 java mysql database

在 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”都是由我“root”创建的,它们有相同的表。我的问题是如何获取它们各自的创建日期。

我找到了这个解决方案:

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_schemamysql 架构以获取您创建的架构:

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 - 用java获取Mysql数据库创建日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11192885/

相关文章:

java - Rational类编写加法和乘法方法

java - 其实例为 volatile 的 Singleton 类是否使实例数据再次加载?

java - Grails:如何让 log.debug 语句显示在控制台中

java - 动态创建具有不同亮度的颜色

MYSQL like 子句找到太多匹配项

mysql - 聚合函数需要GROUP BY吗?

mysql - SAS 中的大字符字段大小

mysql - 音乐播放列表数据库设计

SQL 查询查找第 N 个最高薪水

database - 如何在 react-native 中 realm 数据库检索 nameKey-value?