mybatis执行多条带;(分号)的sql语句报错

报错信息如下:

### The error occurred while setting parameters
### SQL: CREATE DATABASE IF NOT EXISTS test;        USE test;
### Cause: java.sql.SQLSyntaxErrorException: 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 'DATABASE towTable' at line 1
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: 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 'DATABASE towTable' at line 1] with root cause

解决方法 : 在数据库连接配置的url上加上allowMultiQueries=true

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8
    username: root
    password: 123456

你可能感兴趣的:(mysql,mybatis,mybatis)