Skip to content

Commit 1b50dbb

Browse files
committed
refactor[switch-db]: postgre에서 mysql 변경
1 parent 0da3109 commit 1b50dbb

File tree

6 files changed

+52
-21
lines changed

6 files changed

+52
-21
lines changed

backend/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies {
3434
compileOnly 'org.projectlombok:lombok'
3535
developmentOnly 'org.springframework.boot:spring-boot-devtools'
3636
runtimeOnly 'com.h2database:h2'
37-
runtimeOnly 'org.postgresql:postgresql'
37+
runtimeOnly 'com.mysql:mysql-connector-j'
3838
annotationProcessor 'org.projectlombok:lombok'
3939
testImplementation 'org.springframework.boot:spring-boot-starter-test'
4040
testImplementation 'org.springframework.security:spring-security-test'

backend/docker-compose.yml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
version: '3.8'
22

33
services:
4-
postgres:
5-
image: postgres:latest
6-
container_name: postgres
7-
restart: always
4+
mysql:
5+
image: mysql:8.4
6+
container_name: mysql
7+
restart: unless-stopped
88
environment:
9-
POSTGRES_DB: ${DB_NAME}
10-
POSTGRES_USER: ${DB_USER}
11-
POSTGRES_PASSWORD: ${DB_PASS}
9+
MYSQL_DATABASE: ${DB_NAME}
10+
MYSQL_USER: ${DB_USER}
11+
MYSQL_PASSWORD: ${DB_PASS}
12+
# 새 변수: 루트 계정 비번 (필수)
13+
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS}
14+
TZ: Asia/Seoul
1215
ports:
13-
- "${DB_PORT}:${DB_PORT}"
16+
# 호스트 포트는 원하는 값으로, 컨테이너는 3306 고정
17+
- "${DB_PORT:-3306}:3306"
1418
volumes:
15-
- postgres-data:/var/lib/postgresql/data
19+
- mysql-data:/var/lib/mysql
20+
command: >
21+
--character-set-server=utf8mb4
22+
--collation-server=utf8mb4_0900_ai_ci
23+
--default-time-zone=Asia/Seoul
24+
--skip-log-bin
25+
healthcheck:
26+
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-p${DB_ROOT_PASS}"]
27+
interval: 10s
28+
timeout: 5s
29+
retries: 10
1630

1731
volumes:
18-
postgres-data:
32+
mysql-data:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
spring:
22
datasource:
3-
url: jdbc:h2:./db_dev;MODE=PostgreSQL
3+
url: jdbc:h2:./db_dev;MODE=MySQL
44
username: sa
55
password:
66
driver-class-name: org.h2.Driver
Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
spring:
22
datasource:
3-
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
4-
driver-class-name: org.postgresql.Driver
3+
url: jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME}?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Seoul
4+
driver-class-name: com.mysql.cj.jdbc.Driver
55
username: ${DB_USER}
66
password: ${DB_PASS}
7+
hikari:
8+
maximum-pool-size: 20 # 트래픽에 맞춰 조정
9+
minimum-idle: 5
10+
idle-timeout: 30000
11+
connection-timeout: 30000
12+
max-lifetime: 1800000 # MySQL wait_timeout(기본 28800)보다 짧게
713
jpa:
14+
open-in-view: false # 프로덕션 권장
815
hibernate:
9-
ddl-auto: validate
10-
thymeleaf:
11-
cache: true
16+
ddl-auto: validate # 운영 DB는 보통 validate (또는 none)
17+
properties:
18+
hibernate:
19+
dialect: org.hibernate.dialect.MySQL8Dialect # 부트가 자동 감지하지만 명시해도 OK
20+
format_sql: false
21+
sql:
22+
init:
23+
mode: never # 운영에서 스키마 자동 실행 금지
24+
server:
25+
tomcat:
26+
threads:
27+
max: 200
1228
logging:
1329
level:
14-
root: INFO
30+
root: INFO
31+
org.hibernate.SQL: WARN
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
spring:
22
datasource:
3-
url: jdbc:h2:mem:db_test;MODE=PostgreSQL
3+
url: jdbc:h2:mem:db_test;MODE=MySQL
44
username: sa
55
password:
66
driver-class-name: org.h2.Driver

backend/src/main/resources/application.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ spring:
44
application:
55
name: back
66
profiles:
7-
active: dev
7+
active: prod
88
output:
99
ansi:
1010
enabled: always
1111
datasource:
12-
url: jdbc:h2:./db_dev;MODE=PostgreSQL
12+
url: jdbc:h2:./db_dev;MODE=MySQL
1313
username: sa
1414
password:
1515
driver-class-name: org.h2.Driver

0 commit comments

Comments
 (0)