自动创建数据库springboot和mysql

Sac*_*hat 3 java mysql database spring spring-boot

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

spring.jpa.hibernate.ddl-auto=none
spring.datasource.initialization-mode=always
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
Run Code Online (Sandbox Code Playgroud)

Ali*_*ien 6

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

jdbc:mysql://localhost:3306/dbname?createDatabaseIfNotExist=true
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)