Populate MySql DB with initial data from .sql file in Spring boot

hibernate, mysql, pom.xml, spring, spring-boot

Solution

Its very easy! What you need to do is create a sql file in the src/main/resources say data.sql file ; then the query you want say a insert query as :

 insert into admin(username,password,role)  values('admin','admin','role_admin');

Then add dependency :

<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-jdbc</artifactId>
     <version>1.2.4.RELEASE</version>
     </dependency>

And in application.properties file add the following code;

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
     spring.datasource.url=jdbc:mysql://localhost:3306/exampleDB
     spring.datasource.username=root
     spring.datasource.password=root

For more info go through this : link

Problem

I'm using spring boot in combination with MySql DB. I have hibernate to create db tables, but I was wondering what is the easiest way to populate db with initial data such as 'users' by executing some queries from data.sql file? Also what dependencies should I add to pom.xml and properties to application-dev.yml for that matter?

Original source