springboot와 mysql 연결

yeonn·2023년 11월 28일
0

springboot

목록 보기
1/3

springboot 와 mysql 연동해보고자 한다.
먼저 나는 application.properties 파일을 삭제하고 applicaton.yml 파일로 다시 생성해주었다.
application.yml 파일에는 아래 코드를 넣어주었다.

server:
  port: 8082
  servlet:
    context-path: /
    encoding:
      charset: UTF-8
      enabled: true
      force: true

spring:
  application:
    name: user-service
  main:
    allow-circular-references: true
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/[DB스키마]?createDatabaseIfNotExist=true
    username: [mysql유저네임]
    password: [mysql비밀번호]

  jpa:
    hibernate:
      ddl-auto: create #create update none
      naming:
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
    show-sql: true
    properties:
      hibernate:
        format_sql: true

datasource의 url에서 보통은 [DB스키마]? 뒤에 serverTimezone=Asia/Seoul 를 붙인다.
나는 createDatabaseIfNotExist=true 를 붙였는데 그러면 mysql의 스키마와 정상적으로 url연동을 한다고 한다.
이렇게 하면 springboot와 mysql 연동에 성공한다.

profile
개발자에 꽉 눌러 붙은 국문과생

0개의 댓글