auto数据库创建springboot和mysql

x3naxklr  于 2021-06-15  发布在  Mysql
关注(0)|答案(2)|浏览(234)

我尝试在应用程序启动时创建mysql数据库。我已经尝试了以下配置,但无法实现,请让我知道,如果有人对此有想法,

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

fslejnso1#

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

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

你可以在这里找到更详细的参考资料。

ttp71kqs

ttp71kqs2#

如果您正在寻找要创建的数据库,如果不存在,则可以在数据库配置文件中使用下面的命令。

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

相关问题