💾Thananjhayan
← Back to notes

Spring Boot — MySQL Setup & Connection

July 22, 2025

Part (ii). Load the examiner's backup into MySQL, then point Spring Boot at it.

Step 1 — Create the database & restore the backup

The examiner gives you a backup file (usually ending in .sql). Easiest way is MySQL Workbench:

  1. Open MySQL Workbench and connect to your local server (usually user = root).
  2. Create the database — open a query tab and run:
CREATE DATABASE itemdb;
  1. Restore the backup: menu Server → Data Import.
    • Choose Import from Self-Contained File and browse to the given .sql file.
    • Under Default Target Schema choose itemdb (or New… to create it).
    • Click Start Import.

Command-line equivalent, if you prefer:

mysql -u root -p itemdb < backup.sql

Open the restored table and note the exact column names (e.g. itemCode vs item_code) and the database name — they must match the next steps, or the app won't start.

Step 2 — Connect Spring Boot to MySQL

Open src/main/resources/application.properties and add the following, changing the database name and password to match your machine:

spring.datasource.url=jdbc:mysql://localhost:3306/itemdb
spring.datasource.username=root
spring.datasource.password=YOUR_MYSQL_PASSWORD
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
  • localhost:3306 is the standard MySQL address — leave it unless told otherwise.
  • itemdb after the last / must be your real database name.
  • ddl-auto=update means "do not delete my restored data". Never use create or create-drop here, or you lose the backup data.

Next: [[spring-boot-entity]]. Back to [[spring-boot-basics]].

💬 Comments