记一次问题: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,但符合驱动程序早期版本的传统行为。)
名称解释:
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.
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.
参考资料
[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