3

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
Sachetan Bhat
  • 41
  • 1
  • 2
  • Are you looking for something like creating schema automatically if not exists? – Alien Dec 05 '18 at 10:28
  • Please use below link for reference. https://stackoverflow.com/questions/26881739/unable-to-get-spring-boot-to-automatically-create-database-schema – Sushant Dec 05 '18 at 10:30

3 Answers3

6

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
Alien
  • 15,141
  • 6
  • 37
  • 57
0

You should be setting the property with a value that actually creates the schema, for instance:

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

You may find a more detailed reference here.

NiVeR
  • 9,644
  • 4
  • 30
  • 35
0

I have added the following option:

"createDatabaseIfNotExist=true"
spring.datasource.url=jdbc:mysql://localhost:3306/"DB_NAME"?createDatabaseIfNotExist=true
Procrastinator
  • 2,526
  • 30
  • 27
  • 36