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:
- Open MySQL Workbench and connect to your local server (usually user =
root). - Create the database — open a query tab and run:
CREATE DATABASE itemdb;
- Restore the backup: menu Server → Data Import.
- Choose Import from Self-Contained File and browse to the given
.sqlfile. - Under Default Target Schema choose
itemdb(or New… to create it). - Click Start Import.
- Choose Import from Self-Contained File and browse to the given
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.
itemCodevsitem_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:3306is the standard MySQL address — leave it unless told otherwise.itemdbafter the last/must be your real database name.ddl-auto=updatemeans "do not delete my restored data". Never usecreateorcreate-drophere, or you lose the backup data.
Next: [[spring-boot-entity]]. Back to [[spring-boot-basics]].