自动创建数据库springboot和mysql [英] Auto database creation springboot and mysql
本文介绍了自动创建数据库springboot和mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在应用程序启动时创建mysql数据库.我已经尝试过以下配置,但无法实现,请让我知道是否有人对此有所了解,
I am trying create mysql database when application starts up. I have tried with bellow configuration but could not able to achieve, Please let me know if anybody have idea about this,
spring.jpa.hibernate.ddl-auto=none
spring.datasource.initialization-mode=always
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
推荐答案
如果您要创建不存在的数据库,则可以在数据库配置文件中使用.
If you are looking for to create database if not exists then you can use below in database configuration file.
jdbc:mysql://localhost:3306/dbname?createDatabaseIfNotExist=true
否则,请确保您的应用程序属性文件中具有以下属性.
Otherwise make sure you have below properties in your application properties file.
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
这篇关于自动创建数据库springboot和mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文