본문 바로가기
일지

[SpringBoot] MySQL 연동하기

by 닉닉눅 2023. 6. 8.
728x90
반응형

1. MySQL  dependencies 추가

build.gradle에 dependency를 추가합니다.

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    runtimeOnly 'com.mysql:mysql-connector-j' // MySQL dependencies
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

 

2. application.properties에 DB 연결 정보 추가

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/연결DB이름?serverTimezone=UTC&characterEncoding=UTF-8
spring.datasource.username=아이디
spring.datasource.password=비밀번호

 

이후 실행 하면 스프링부트가 잘 실행되는 것을 볼 수 있습니다.

 

728x90
반응형

댓글