Spring Boot DB 변경

ysh·2023년 10월 3일
0

Spring Boot

목록 보기
52/53
post-custom-banner

H2->mariaDB

bulid.gradle 의존성 추가

yml 변경

변경 전

spring:
  thymeleaf:
    cache: false
  datasource:
    url: jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_DELAY=-1
    driverClassName: org.h2.Driver
    username: sa
    password:
  h2:
    console:
      enabled: true
      path: /h2
  sql:
    init:
      encoding: UTF-8
#      schema-locations: classpath:h2/schema.sql
      dataLocations: classpath:h2/data.sql
      mode: always
  jpa:
    defer-datasource-initialization: true
    open-in-view: false # 트랜잭션 범위 밖에서 영속성 컨텍스트를 유지할지 여부
    database-platform: org.hibernate.dialect.H2Dialect
    hibernate:
      ddl-auto: create # create-drop, update, validate, none
      naming:
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
        implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
    show-sql: true
    properties:
      hibernate:
        format_sql: true
        use_sql_comments: true
        default_batch_fetch_size: 500
  servlet:
    multipart:
      max-request-size: 10MB
      max-file-size: 10MB

변경 후

spring:
  thymeleaf:
    cache: false
  datasource:
    # TODO : 테스트 디비 / 실디비 구분
    # url: jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_DELAY=-1
    # driverClassName: org.h2.Driver
    # username: sa
    # password:

    url: jdbc:mariadb://localhost:3306/testdb
    driverClassName: org.mariadb.jdbc.Driver
    username: root
    password: "1234"
  # h2:
  #   console:
  #     enabled: true
  #     path: /h2
  sql:
    init:
      encoding: UTF-8
#      schema-locations: classpath:h2/schema.sql
      dataLocations: classpath:h2/data.sql
      mode: always
  jpa:
    defer-datasource-initialization: true
    open-in-view: false # 트랜잭션 범위 밖에서 영속성 컨텍스트를 유지할지 여부
    # database-platform: org.hibernate.dialect.H2Dialect
    database-platform: org.hibernate.dialect.MariaDBDialect
    hibernate:
      ddl-auto: create # create-drop, update, validate, none
      naming:
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
        implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
    show-sql: true
    properties:
      hibernate:
        format_sql: true
        use_sql_comments: true
        default_batch_fetch_size: 500
  servlet:
    multipart:
      max-request-size: 10MB
      max-file-size: 10MB

db 생성

db 확인


mariaDB -> H2

서버에 resource - h2 폴더 생성해서 data.sql

build.gradle 변경

h2 콘솔에서 쿼리문 뽑기

script table todo;

profile
유승한
post-custom-banner

0개의 댓글