【问题标题】:Auto database creation springboot and mysql自动创建数据库 springboot 和 mysql
【发布时间】:2019-05-06 21:23:31
【问题描述】:

我正在尝试在应用程序启动时创建 mysql 数据库。我尝试了以下配置,但无法实现,如果有人对此有任何想法,请告诉我,

spring.jpa.hibernate.ddl-auto=none
spring.datasource.initialization-mode=always
spring.jpa.properties.hibernate.globally_quoted_identifiers=true

【问题讨论】:

标签: java mysql database spring spring-boot


【解决方案1】:

您应该使用实际创建架构的值设置属性,例如:

spring.jpa.hibernate.ddl-auto=create-drop

您可以找到更详细的参考资料here

【讨论】:

    【解决方案2】:

    如果您正在寻找创建数据库(如果不存在),那么您可以在数据库配置文件中使用下面的内容。

    jdbc:mysql://localhost:3306/dbname?createDatabaseIfNotExist=true
    

    否则,请确保您的应用程序属性文件中有以下属性。

    spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
    spring.jpa.hibernate.ddl-auto=update
    spring.datasource.driverClassName=com.mysql.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:3306/dbname
    spring.datasource.username=username
    spring.datasource.password=password
    

    【讨论】:

      猜你喜欢
      • 2014-08-08
      • 2011-10-21
      • 2017-08-18
      • 2020-02-10
      • 1970-01-01
      • 1970-01-01
      • 2014-01-30
      • 2016-01-09
      • 2021-04-21
      相关资源
      最近更新 更多