How to get your DB Tables automatically created with Spring Boot

Here is a sample application.properties configuration that will let Hibernate create the Database tables out of your Entity beans:

spring.datasource.url=jdbc:mysql://localhost:3306/mysqltutorial?useSSL=false
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto = create

Here are the possible values for hibernate.hbm2ddl.auto :

  • validate: validate the schema, makes no changes to the database.
  • update: update the schema.
  • create: creates the schema, destroying previous data
  • create-drop: drop the schema at the end of the session

Additionally, if you want to log the schema creation, include these properties as well in your application.properties file:

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE