【问题标题】:Spring Boot Error executing DDL via JDBC Statement通过 JDBC 语句执行 DDL 的 Spring Boot 错误
【发布时间】:2021-01-08 16:55:19
【问题描述】:

所以我想制作一个简单的 CRUD 应用程序,我使用 MYSQL Workbench 作为数据库。 我在 MySQL Workbench 中的连接

Hostname : 127.0.0.1
Port : 3306

我不在 MySQL Workbench 中使用密码。

现在我的应用程序属性看起来像这样

spring.datasource.url=jdbc:mysql://localhost:3306/employee_management_system?useSSL=false
spring.datasource.username=root
spring.datasource.password=

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLInnoDBDialect

spring.jpa.hibernate.ddl-auto=update

我遇到的错误

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table employees (id bigint not null auto_increment, email_id varchar(255), first_name varchar(255), last_name varchar(255), primary key (id)) type=InnoDB" via JDBC Statement

还有一个在底部

Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'type=InnoDB' at line 1

有人可以帮忙吗?

【问题讨论】:

标签: spring spring-boot spring-mvc spring-data-jpa


【解决方案1】:

改用这个查询:

create table employees 
  ( 
     id         bigint not null auto_increment, 
     email_id   varchar(255), 
     first_name varchar(255), 
     last_name  varchar(255), 
     primary key (id) 
  ) 
engine=InnoDB; 

供参考:Using "TYPE = InnoDB" in MySQL throws exception

【讨论】:

    【解决方案2】:

    我认为您的数据库不支持 InnoDB 引擎。 尝试替换

    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLInnoDBDialect
    

    通过

    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
    

    【讨论】:

      【解决方案3】:

      在我的情况下,我需要通过将这两行添加到我的 application.properties 文件来检查它生成的 sql

      spring.jpa.show-sql=true
      spring.jpa.properties.hibernate.format_sql=true 
      

      只有这样我才能复制 sql,将其粘贴到控制台编辑器中并获得更详细的错误描述。它在那里抱怨我试图用保留字命名我的表。我改变了它并且它起作用了(我使用的是 postgres)。

      【讨论】:

        【解决方案4】:

        问题是您现在尝试访问不存在的数据库或默认的“information_schema”,该用户不允许如此简单地在其上创建表

        创建一个新的数据库:

        create database example;
        

        创建一个新用户来处理这个数据库,或者您可以使用 root 访问权限,但新用户最好不要在任何地方使用 root 用户

        create user 'exampleuser'@'%' identified by 'PASSWORD;
        

        然后分配用户对该数据库拥有所有权限

        grant all on example.* to 'exampleuser'@'%';
        

        最后,确保更新你的 spring 配置

        spring.jpa.hibernate.ddl-auto=update
        spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/example
        spring.datasource.username=exampleuser
        spring.datasource.password=12345
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-10-21
          • 1970-01-01
          • 2019-03-30
          • 1970-01-01
          • 1970-01-01
          • 2017-10-20
          • 2017-08-28
          • 2022-09-29
          相关资源
          最近更新 更多