MyBatis 为 MySQL 创建多个表

MyBatis create multiple tables for MySQL

如你所想,

CREATE TABLE table1(id int);
CREATE TABLE table2(id int);

在 MySQL 和几乎所有其他 SQL 数据库上都很容易执行。

这个

<update id="test">
  CREATE TABLE table1(id int);
  CREATE TABLE table2(id int);
</update>

在 MS SQL 服务器上可执行,但在 MySQL- 数据库上不可执行。错误:

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE table2(id int)' at line 2
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: CREATE TABLE table1(id int); CREATE TABLE table2(id int);

有什么想法,为什么会这样?

编辑:

<update id="test">
  CREATE TABLE table(id int);
</update>

..无处不在。

编辑说明: 我完整的mybatis mapper.xml.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="InitializationMapper">
   <update id="test">
      CREATE TABLE table1(id int);
      CREATE TABLE table2(id int);
   </update>
</mapper>

尝试将 "allowMultiQueries" 选项添加到您的 Mybatis 配置文件中的 JDBC URL,例如:

jdbc:mysql://myserver/mydatabase?allowMultiQueries=true

这似乎对这里的人有用:Multiple queries executed in java in single statement