Spring Boot和MySQL自动创建数据库

3

我正在尝试在应用程序启动时创建MySQL数据库。 我已经尝试了以下配置,但无法实现,请告诉我是否有人对此有想法,

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

你是否正在寻找类似于自动创建模式(schema)的功能,如果不存在的话? - Alien
请使用以下链接作为参考:https://dev59.com/uF8d5IYBdhLWcg3wYxY- - Sushant
3个回答

6

如果您想要创建数据库,如果不存在的话,您可以在数据库配置文件中使用以下内容。

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

0

我已添加了以下选项:

"createDatabaseIfNotExist=true"
spring.datasource.url=jdbc:mysql://localhost:3306/"DB_NAME"?createDatabaseIfNotExist=true

0

你应该使用能够实际创建模式的值来设置属性,例如:

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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接