Skip to content

Commit 0b24c3f

Browse files
committed
chore(project): DB 구축 (#4)
- DB 구축 - 각 개발 환경에 따른 DB 연결과 로깅 설정 구분 - 문서화 Closes #4
1 parent e605a1a commit 0b24c3f

File tree

7 files changed

+465
-1
lines changed

7 files changed

+465
-1
lines changed
File renamed without changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Docker Compose MySQL에 외부 도구로 연결하기
2+
### 1. 현재 포트 확인하기
3+
현재 파일에서 MySQL 포트가 `- '3306'` 형태로 설정되어 있습니다. 이는 Docker가 호스트의 랜덤 포트에 MySQL의 3306 포트를 매핑한다는 의미입니다. 먼저 실제 매핑된 포트를 확인해야 합니다: `compose.yaml`
4+
``` bash
5+
docker ps
6+
```
7+
또는
8+
``` bash
9+
docker-compose ps
10+
```
11+
명령어를 실행하면 다음과 비슷한 출력이 표시됩니다:
12+
```
13+
NAME IMAGE ... PORTS ...
14+
mysql mysql:latest ... 0.0.0.0:32769->3306/tcp ...
15+
```
16+
여기서 32769는 호스트 머신에서 MySQL에 접근할 수 있는 포트 번호입니다.
17+
### 2. 데이터그립에서 연결하기
18+
1. 데이터그립을 실행하고 새 데이터 소스를 생성합니다.
19+
2. MySQL을 선택합니다.
20+
3. 다음 정보를 입력합니다:
21+
- 호스트(Host): localhost
22+
- 포트(Port): 32769 (또는 `docker ps` 명령어로 확인한 포트)
23+
- 사용자(User): 일반 사용자 접속은 `myuser`, 관리자 접속은 `root`
24+
- 비밀번호(Password): 일반 사용자는 `secret`, root 사용자는 `verysecret`
25+
- 데이터베이스(Database): `mydatabase`
26+
27+
4. '테스트 연결'을 클릭하여 연결이 성공하는지 확인합니다.
28+
29+
### 3. MySQL 콘솔로 연결하기
30+
터미널이나 명령 프롬프트에서:
31+
``` bash
32+
# 일반 사용자로 연결
33+
mysql -h127.0.0.1 -P32769 -umyuser -psecret mydatabase
34+
35+
# 또는 root 사용자로 연결
36+
mysql -h127.0.0.1 -P32769 -uroot -pverysecret
37+
```

documents/Undabang Database SQL.sql

Lines changed: 366 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
spring:
2+
datasource:
3+
url: jdbc:mysql://localhost:3306/mydatabase
4+
username: myuser
5+
password: secret
6+
driver-class-name: com.mysql.cj.jdbc.Driver
7+
8+
jpa:
9+
properties:
10+
hibernate:
11+
format_sql: true
12+
use_sql_comments: true
13+
14+
transaction:
15+
default-timeout: 60s
16+
17+
logging:
18+
level:
19+
store.undabang: debug # 애플리케이션 로그
20+
org.hibernate.SQL: debug # SQL 쿼리 로깅
21+
org.hibernate.orm.jdbc.bind: trace # SQL 파라미터 바인딩 로깅 (Hibernate 6.x)
22+

src/main/resources/application.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ spring:
66
active: local
77

88
jpa:
9-
open-in-view: false
9+
open-in-view: false
10+
database-platform: org.hibernate.dialect.MySQL8Dialect
11+
hibernate:
12+
ddl-auto: validate
13+

src/test/resources/application.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
spring:
2+
datasource:
3+
url: jdbc:h2:mem:testdb;MODE=MySQL;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE;DB_CLOSE_DELAY=-1
4+
username: sa
5+
password:
6+
7+
jpa:
8+
defer-datasource-initialization: true
9+
database-platform: org.hibernate.dialect.H2Dialect
10+
hibernate:
11+
ddl-auto: create-drop
12+
properties:
13+
hibernate:
14+
format_sql: true
15+
use_sql_comments: true
16+
dialect: org.hibernate.dialect.H2Dialect
17+
18+
h2:
19+
console:
20+
enabled: true
21+
path: /h2-console
22+
23+
sql:
24+
init:
25+
mode: always
26+
data-locations: classpath:test-data.sql
27+
28+
transaction:
29+
default-timeout: 30s
30+
31+
logging:
32+
level:
33+
store.undabang: debug
34+
org.hibernate.SQL: debug
35+
org.hibernate.orm.jdbc.bind: trace

src/test/resources/test-data.sql

Whitespace-only changes.

0 commit comments

Comments
 (0)