less than 1 minute read

  • MAC์—์„œ MySQL WORKBENCH ์‚ฌ์šฉํ•œ ์Šคํ”„๋ง๋ถ€ํŠธ + MySQL + JPA ์—ฐ๋™ํ•˜๊ธฐ
    • ํ•ญ์ƒ ์ฒซ๊ฑธ์Œ์€ ์„ธํŒ…๋ถ€ํ„ฐ๋‹ค๐Ÿ› 
  1. MySQL ์„œ๋ฒ„๋ฅผ ๊ตฌ๋™์‹œ์ผœ ์ค€๋‹ค.(terminal)
    • cd /usr/local/mysql/bin/
    • ./mysql -uroot -p
    • password ์ž…๋ ฅ
  2. WORKBENCH ๐Ÿฌ์—์„œ create a new schemas ๋กœ ์ƒˆ๋กœ์šด ์Šคํ‚ค๋งˆ(DB)๋ฅผ ๋งŒ๋“ค์–ด ์ค€๋‹ค.

  3. build.gradle์— ์•„๋ž˜ dependency๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.
     dependencies {
         implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
         implementation 'mysql:mysql-connector-java'
     }
    
  4. ์•„๋ž˜์˜ ์„ค์ •์œผ๋กœ properties ๋‚˜ yml ํŒŒ์ผ์˜ ๋‚ด์šฉ์„ ์„ธํŒ…ํ•ด์ค€๋‹ค.

     # MySQL ์„ค์ •
     spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
     # DB Source URL
     spring.datasource.url=jdbc:mysql://<IP>:<PORT>/<DB NAME>?useSSL=false&useUnicode=true&serverTimezone=Asia/Seoul
     spring.datasource.url=jdbc:mysql://localhost:3306/testdb?characterEncoding=UTF-8&serverTimezone=UTC
     # DB usernamer
     spring.datasource.username=<MySQL USERNAME>
     # DB password
     spring.datasource.password=<MySQL PASSWORD>
     logging.level.com.example = debug
     spring.jpa.properties.hibernate.format_sql=true
     spring.jpa.properties.hibernate.show_sql = true
     #spring.jpa.hibernate.ddl-auto=create
     spring.jpa.hibernate.ddl-auto=update
    

spring.jpa.hibernate.dll-auto : create, create-drop, update, validate, none ์˜ต์…˜ ์„ค์ • ๊ฐ€๋Šฅ

  • create : JPA๊ฐ€ DB์™€ ์ƒํ˜ธ์ž‘์šฉํ•  ๋•Œ ๊ธฐ์กด์— ์žˆ๋˜ ์Šคํ‚ค๋งˆ(ํ…Œ์ด๋ธ”)์„ ์‚ญ์ œํ•˜๊ณ  ์ƒˆ๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์„ ๋œปํ•จ
    • ํ…Œ์ŠคํŠธ ์šฉ๋„๋กœ ์ž์ฃผ ์‚ฌ์šฉ
  • create-drop : JPA ์ข…๋ฃŒ ์‹œ์ ์— ๊ธฐ์กด์— ์žˆ์—ˆ๋˜ ํ…Œ์ด๋ธ”์„ ์‚ญ์ œ

  • update : JPA์— ์˜ํ•ด ๋ณ€๊ฒฝ๋œ ๋ถ€๋ถ„๋งŒ ๋ฐ˜์˜
    • ์‹ค์ œ ์„œ๋น„์Šค์™€ ๋น„์Šทํ•œ ํ™˜๊ฒฝ์ด๋ผ๊ณ  ๊ฐœ์ธ์ ์œผ๋กœ ์ƒ๊ฐ
  • validate : ์—”ํ‹ฐํ‹ฐ์™€ ํ…Œ์ด๋ธ”์ด ์ •์ƒ ๋งคํ•‘๋˜์–ด ์žˆ๋Š”์ง€๋งŒ ๊ฒ€์ฆ

  • none : ์ดˆ๊ธฐํ™” ๋™์ž‘์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค

spring.jpa.show-sql: JPA๊ฐ€ ์ƒ์„ฑํ•œ SQL๋ฌธ์„ ๋ณด์—ฌ์ค„ ์ง€์— ๋Œ€ํ•œ ์—ฌ๋ถ€๋ฅผ ์•Œ๋ ค์ฃผ๋Š” ํ”„๋กœํผํ‹ฐ์ด๋‹ค.

spring.jpa.generate-dll:

spring.jpa.hibernate.dll-auto ์˜ต์…˜์„ ์‚ฌ์šฉํ•  ๊ฒƒ์ธ์ง€๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ํ”„๋กœํผํ‹ฐ์ด๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ false๋กœ ๋˜์–ด์žˆ๊ธฐ ๋•Œ๋ฌธ์— JPA์— ์˜ํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ž๋™ ์ดˆ๊ธฐํ™” ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด true๋กœ ์„ธํŒ…ํ•ด์•ผ ํ•œ๋‹ค.

Reference ๐Ÿ“

https://engkimbs.tistory.com/794

Leave a comment