본문 바로가기
SpringBoot/ETC

SpringBoot에 MYSQL 연동

by BAYABA 2021. 10. 14.
  1. 개인 공부 목적으로 작성한 글입니다.
  2. 아래 출처를 참고하여 작성하였습니다.

목차

  1. build.gradle
  2. application.yml

1. build.gradle

dependencies {
   //...
   runtimeOnly 'mysql:mysql-connector-java'
}

2. application.yml

  1. driver-class-name
  • com.mysql.jdbc.Driver와 com.mysql.cj.jdbc.Driver 두가지가 있습니다.
  • 전자는 Deprecated이므로 com.mysql.cj.jdbc.Driver를 사용하도록 합니다.
  1. url
  • localhost:3306/test
  • test는 database 이름을 의미합니다.
  • serverTimezone=UTC
  • URL 쿼리 스트링에 serverTimezone을 작성해줘야 에러가 발생하지 않으므로 꼭 작성하도록 합니다.
  1. username / password
  • 계정명과 비밀번호를 작성하면 됩니다.
  • 해당 계정에 DB에 접근할 수 있는 권한이 이미 부여되어 있어야 합니다.
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test?serverTimezone=UTC&characterEncoding=UTF-8
    username: user_id
    password: 11111111
    driver-class-name: com.mysql.cj.jdbc.Driver

출처

  1. [SpringBoot] Mysql 연동

'SpringBoot > ETC' 카테고리의 다른 글

SQL 보기 옵션 정리  (0) 2021.10.14
@Builder 사용 시 주의 점  (0) 2021.10.08
생성자 주입 방식의 장점  (0) 2021.10.01