mybatis generator 生成其他库同名表

记一次问题:mybatis generator 生成了其他库同名表。
解决1:

<jdbcConnection driverClass="com.mysql.jdbc.Driver"
                      connectionURL="jdbc:mysql://xxxxxx/a“
                      userId="root"
                      password="xxxxxx">
	<!--防止生成其他库同名表-->
	<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>

解决2:

<jdbcConnection driverClass="com.mysql.jdbc.Driver"
              connectionURL="jdbc:mysql://xxxxxx/a?nullCatalogMeansCurrent=true“
              userId="root"
              password="xxxxxx">
</jdbcConnection>

官方解释:
MySql不能正确支持SQL catalogs和schema。如果 在MySql中运行create schema命令,它实际上会创建一个数据库 - 并且JDBC驱动程序将其作为catalogs报告回来。但是MySql语法不支持标准的catalog…table SQL语法。
因此,最好不要在generator 配置中指定catalog或schema。只需指定表名并在JDBC URL中指定数据库即可。
如果您使用的是mysql-connector-java的8.x版,生成器可能会尝试为MySql information schemas中的表生成代码。要禁用此行为,请将属性“nullCatalogMeansCurrent = true”添加到JDBC URL。

MySql does not properly support SQL catalogs and schema. If you run the create schema command in MySql, it actually creates a database - and the JDBC driver reports it back as a catalog. But MySql syntax does not support the standard catalog…table SQL syntax.
For this reason, it is best to not specify either catalog or schema in generator configurations. Just specify table names and specify the database in the JDBC URL.
If you are using version 8.x of Connector/J you may notice that the generator attempts to generate code for tables in the MySql information schemas (sys, information_schema, performance_schema, etc.) This is probably not what you want! To disable this behavior, add the property “nullCatalogMeansCurrent=true” to your JDBC URL.

扩展:

nullCatalogMeansCurrent 解释:
当DatabaseMetadataMethods请求“catalogs ”参数,值为“Null”时是否意味着使用当前catalogs。( 它不兼容JDBC,但符合驱动程序早期版本的传统行为。)

名称解释:

  • information schemas
    information schemas数据库提供mysql数据字典查询接口。提供了数据库元数据的访问方式,记录了大部分我们需要了解的信息。

    The name of the database that provides a query interface to the MySQL data dictionary. (This name is defined by the ANSI SQL standard.) To examine information (metadata) about the database, you can query tables such as INFORMATION_SCHEMA.TABLES and INFORMATION_SCHEMA.COLUMNS, rather than using SHOW commands that produce unstructured output.

  • schema
    在MySQL中,物理上,schema与database是同义词。在MySQL SQL语法中,可以用关键字schema替换database,例如使用CREATE SCHEMA而不是 CREATE DATABASE

In MySQL, physically, a schema is synonymous with a database. You can substitute the keyword SCHEMA instead of DATABASE in MySQL SQL syntax, for example using CREATE SCHEMA instead of CREATE DATABASE.

  • catalogs
    在mysql官网,没看到相关的解释。Stack Overflow有个回答说mysql中,database == schema == catalog ==服务器中的命名空间。但其他网站也有人说,database == schema, catalog 等于database的集合。 这个如果有知道,望告知。

参考资料
[1]解决方案:http://www.mybatis.org/generator/usage/mysql.html
[2] schema解释:https://dev.mysql.com/doc/refman/8.0/en/glossary.html#glos_schema
[3] information schema解释:https://dev.mysql.com/doc/refman/8.0/en/glossary.html#glos_information_schema
[4]Stack Overflow的回答:https://stackoverflow.com/questions/7942520/relationship-between-catalog-schema-user-and-database-instance
[5]其他关于catalog的解释:https://wenku.baidu.com/view/61db797701f69e31433294e6.html

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值