Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto database creation springboot and 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
like image 977
Sachetan Bhat Avatar asked Jun 28 '26 04:06

Sachetan Bhat


1 Answers

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
like image 144
Alien Avatar answered Jun 29 '26 18:06

Alien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!