__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"40f3f":{"name":"Main Accent","parent":-1}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"40f3f":{"val":"var(--tcb-color-0)"}},"gradients":[]},"original":{"colors":{"40f3f":{"val":"rgb(127, 215, 132)","hsl":{"h":123,"s":0.52,"l":0.67,"a":1}}},"gradients":[]}}]}__CONFIG_colors_palette__

__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"40f3f":{"name":"Main Accent","parent":-1}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"40f3f":{"val":"var(--tcb-color-0)"}},"gradients":[]},"original":{"colors":{"40f3f":{"val":"rgb(127, 215, 132)","hsl":{"h":123,"s":0.52,"l":0.67,"a":1}}},"gradients":[]}}]}__CONFIG_colors_palette__
Table of Contents

In this post, we will discuss how to configure MySQL for Spring Boot application. We will get into details for the support provided by Spring Boot for MySQL database.



Spring Boot provides a ready-to-use support for H2 Database.Spring Boot automatically set up in memory H2 database if it detects H2 configurations in the classpath.This is superb to work on the development project, however, most of the enterprise projects use production level databases like MySQL, Oracle, etc.

Spring Boot has support for MySQL and other popular relational databases.In this post, we will focus on configuring Spring Boot for MySQL database.


1. MySQL Database Configuration

I will not cover installing MySQL server on your machine or how to create a new database in the MySQL. For this post, I assume that we have already installed MySQL on your machine.Please create a new database on the MySQL server (Let’s call this new database as javadevjournal).


2. Adding MySQL Dependencies

To enable support for MySQL in our project, we need to add spring-boot-starter-data-jpa and mysql-connector-java starter in the pom.xml file.

  <!-- JPA Data (We are going to use Repositories, Entities, Hibernate, etc...) -->
  <!-- Use MySQL Connector-J -->

Spring Boot auto-configure DataSource if spring-boot-starter-data-jpa is in the classpath by reading database configurations defined in the application.properties.


3. Configure MySQL Using Spring Boot Properties

By Default, Spring Boot provides database configurations for the H2 database.To use MySQL for our application, we need to override these default configurations.Once we define DB properties in the project’s application.properties file, Spring Boot will not set up default database anymore.


## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect

The property spring.jpa.hibernate.ddl-auto is for database initialization. It is good security practice that after your database is in production state, you make this none. Here are some commonly used ddl values:

  • none: The default for MySQL. We make no change to the database structure.
  • update: Hibernate changes the database according to the entity structures.
  • create: Creates the database every time but does not drop it on close.
  • create-drop: Creates the database and drops it when SessionFactory closes.

[pullquote align=”normal”]While setting up JPA properties, We need not specify the driver or the dialect. These are detected automatically. If you want to customize these properties, feel free to add/customize using application.properties file. [/pullquote].

These are the only configuration changes required to use MySQL with your Spring Boot application.Once you start your application, Spring Boot will use MySQL as your underlying database.



In this short post, we covered configure MySQL for Spring Boot application.We learned how to override default data source configurations provided by Spring Boot to use MySQL as the underlying database.

4 1 vote
Article Rating

Related Posts

Java Development Journal

Hello!! Welcome to the Java Development Journal. We love to share our knowledge with our readers and love to build a thriving community.

Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
Would love your thoughts, please comment.x