使用 SchemaCrawler 时无法检索列的注释,但无法检索 table

Can't retrieve the comment for columns but not table when using SchemaCrawler

我正在使用 SchemaCrawler 获取 MySQL5.7 tables 的元数据,使用以下代码:

final Connection connection = ...;
final DatabaseSpecificOverrideOptions databaseSpecificOverrideOptions =
                        SchemaCrawlerUtility.matchDatabaseSpecificOverrideOptions(connection);

final SchemaCrawler schemaCrawler = new SchemaCrawler(connection, databaseSpecificOverrideOptions);

final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
options.setSchemaInfoLevel(SchemaInfoLevelBuilder.maximum());
options.setTableInclusionRule(new IncludeAll());
options.setColumnInclusionRule(new IncludeAll());

final Catalog catalog = schemaCrawler.crawl(options);
final Collection<Table> tables = catalog.getTables();

for (Table t : tables) {
    logger.info("Table comment: {}", t.getRemarks());
}

这是测试table:

create table testtable (
    id bigint comment 'key level comment', 
    name varchar(32) comment 'column level comment'
) comment='table level comment';

能拿到专栏级的评论,但是我永远拿不到table级的评论。

有没有我配置错误的东西?

谢谢!

这是 MySQL JDBC 驱动程序的一个烦恼。创建连接时,您需要在 JDBC 连接 URL 中设置 useInformationSchema=true。有关更多信息,请查看 Whosebug 问题,Retrieve mysql table comment using DatabaseMetaData

Sualeh Fatehi,SchemaCrawler