Cloud SQL(finders-db)์ ๋ก์ปฌ IDE์์ ์ ์ํ๋ ๋ฐฉ๋ฒ
Cloud SQL์ ๊ณต๊ฐ IP๊ฐ ๋นํ์ฑํ๋์ด ์์ด IAP ํฐ๋์ ํตํด์๋ง ์ ์ ๊ฐ๋ฅํฉ๋๋ค.
[๋ก์ปฌ PC] โ [IAP ํฐ๋] โ [GCE ์๋ฒ] โ [Cloud SQL]
localhost:3307 โ ์ํธํ๋ ํฐ๋ โ 10.0.2.2 โ 10.68.240.3:3306
์์ง ์ค์นํ์ง ์์๋ค๋ฉด Google Cloud SDK๋ฅผ ์ค์นํ์ธ์.
# ์ค์น ํ์ธ
gcloud --version# Google ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธ (๋ธ๋ผ์ฐ์ ์ด๋ฆผ)
gcloud auth login
# Application Default Credentials ์ค์
gcloud auth application-default login
# ํ๋ก์ ํธ ์ค์
gcloud config set project finders-487717IAP ํฐ๋ ์ฌ์ฉ์ ์ํด ๋ค์ ๊ถํ์ด ํ์ํฉ๋๋ค:
roles/iap.tunnelResourceAccessor(IAP ํฐ๋ ์ ๊ทผ)roles/compute.viewer(Compute Engine ์กฐํ)
๊ถํ์ด ์๋ค๋ฉด ํ๋ก์ ํธ ๊ด๋ฆฌ์์๊ฒ ์์ฒญํ์ธ์.
ํฐ๋ฏธ๋์ ์ด๊ณ ์๋ ๋ช ๋ น์ด๋ฅผ ์คํํฉ๋๋ค. (์ ์ ์ค์๋ ํฐ๋ฏธ๋์ ๋ซ์ง ๋ง์ธ์!)
gcloud compute ssh finders-server \
--zone=asia-northeast3-a \
--project=finders-487717 \
--tunnel-through-iap \
-- -L 3307:10.68.240.3:3306๋ณด์ ์๋ด: ์ ๋ช ๋ น์ด์ ํฌํจ๋ ์ ๋ณด(Project ID, Private IP ๋ฑ)๋ ๊ณต๊ฐ๋์ด๋ ๋ณด์ ์ํ์ด ์์ต๋๋ค.
- IAP ์ธ์ฆ: GCP IAM ๊ถํ์ด ์์ผ๋ฉด ํฐ๋ ์์ฒด๊ฐ ์ด๋ฆฌ์ง ์์
- Private IP: VPC ๋ด๋ถ IP๋ผ ์ธ๋ถ์์ ์ง์ ์ ๊ทผ ๋ถ๊ฐ๋ฅ
- ์ค์ ๋ฏผ๊ฐ ์ ๋ณด(๋น๋ฐ๋ฒํธ ๋ฑ)๋ ์ด ๋ฌธ์์ ํฌํจ๋์ด ์์ง ์์ต๋๋ค.
์ฑ๊ณตํ๋ฉด ์๋์ ๊ฐ์ ๋ฉ์์ง๊ฐ ์ถ๋ ฅ๋ฉ๋๋ค:
Warning: Permanently added 'compute.xxxxx' (ED25519) to the list of known hosts.
Welcome to Ubuntu 22.04...
์ฃผ์: ์ด ํฐ๋ฏธ๋ ์ฐฝ์ DB ์์ ์ด ๋๋ ๋๊น์ง ์ด์ด๋์ธ์!
ํฐ๋์ด ์ด๋ฆฐ ์ํ์์ ์ ํฐ๋ฏธ๋ ๋๋ IDE์์ DB์ ์ฐ๊ฒฐํฉ๋๋ค.
| ํญ๋ชฉ | ๊ฐ |
|---|---|
| Host | localhost |
| Port | 3307 |
| User | finders |
| Password | .env.dev ๋๋ .env.prod ์ฐธ์กฐ |
| Database | finders_dev (๊ฐ๋ฐ) / finders (์ด์) |
- View > Tool Windows > Database ๋๋ ์ฐ์ธก ์ฌ์ด๋๋ฐ Database ํด๋ฆญ
- + > Data Source > MySQL ์ ํ
- ์ฐ๊ฒฐ ์ ๋ณด ์
๋ ฅ:
- Host:
localhost - Port:
3307 - User:
finders - Password: (ํ ๊ณต์ ๋ฌธ์ ์ฐธ์กฐ)
- Database:
finders_dev
- Host:
- Test Connection ํด๋ฆญํ์ฌ ์ฐ๊ฒฐ ํ์ธ
- OK ํด๋ฆญ
- File > New > Data Source > MySQL
- ์ฐ๊ฒฐ ์ ๋ณด ์ ๋ ฅ (IntelliJ์ ๋์ผ)
- Test Connection โ OK
์ฃผ์: Database Client(cweijan)๋ 3๊ฐ ์ฐ๊ฒฐ ์ด๊ณผ ์ ์ ๋ฃ์ ๋๋ค. SQLTools(mtxr)๋ฅผ ์ถ์ฒํฉ๋๋ค!
์ค์น:
- Extensions์์ SQLTools (mtxr) ์ค์น
- Extensions์์ SQLTools MySQL/MariaDB ๋๋ผ์ด๋ฒ ์ค์น
์ฐ๊ฒฐ ์ค์ :
- ์ข์ธก ์ฌ์ด๋๋ฐ SQLTools ์์ด์ฝ ํด๋ฆญ
- Add New Connection ํด๋ฆญ
- MySQL ์ ํ
- ์ฐ๊ฒฐ ์ ๋ณด ์
๋ ฅ:
- Connection Name:
Finders Dev - Server:
localhost - Port:
3307 - Database:
finders_dev - Username:
finders - Password: (ํ ๊ณต์ ๋ฌธ์ ์ฐธ์กฐ)
- Connection Name:
- Test Connection โ Save Connection
- MySQL Connections ์ + ํด๋ฆญ
- ์ฐ๊ฒฐ ์ ๋ณด ์
๋ ฅ:
- Connection Name:
Finders Dev (IAP Tunnel) - Hostname:
localhost - Port:
3307 - Username:
finders
- Connection Name:
- Test Connection โ ๋น๋ฐ๋ฒํธ ์ ๋ ฅ โ OK
mysql -h localhost -P 3307 -u finders -p finders_dev| ํ๊ฒฝ | Database | ์ฉ๋ |
|---|---|---|
finders_dev |
๊ฐ๋ฐ DB | FE ์ฐ๋ ํ ์คํธ, Mock ๋ฐ์ดํฐ |
finders |
์ด์ DB | ์ค์ ์๋น์ค ๋ฐ์ดํฐ (์ฃผ์!) |
์ฃผ์: ์ด์ DB(
finders)์์ DELETE/UPDATE ์์ ์ ๊ฐ๋ณํ ์ฃผ์ํ์ธ์!
ERROR: (gcloud.compute.ssh) Could not fetch resource
ํด๊ฒฐ: IAM ๊ถํ์ด ์์ต๋๋ค. ํ๋ก์ ํธ ๊ด๋ฆฌ์์๊ฒ roles/iap.tunnelResourceAccessor ๊ถํ์ ์์ฒญํ์ธ์.
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3307'
ํด๊ฒฐ:
- IAP ํฐ๋์ด ์ด๋ ค์๋์ง ํ์ธ (Step 1์ ํฐ๋ฏธ๋์ด ์คํ ์ค์ธ์ง)
- ํฌํธ๊ฐ ๋ง๋์ง ํ์ธ (
3307)
ERROR 1045 (28000): Access denied for user 'finders'@'xxx'
ํด๊ฒฐ: ๋น๋ฐ๋ฒํธ๊ฐ ํ๋ฆฝ๋๋ค. ํ ๊ณต์ ๋ฌธ์์์ ์ต์ ๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํ์ธ์.
์ฅ์๊ฐ ๋ฏธ์ฌ์ฉ ์ ํฐ๋์ด ์๋์ผ๋ก ๋์ด์ง ์ ์์ต๋๋ค. Step 1์ ๋ค์ ์คํํ์ธ์.
ํฐ๋ฏธ๋ ์ฐฝ์ ์ด์ด๋๊ธฐ ์ซ๋ค๋ฉด ๋ฐฑ๊ทธ๋ผ์ด๋๋ก ์คํ:
gcloud compute ssh finders-server \
--zone=asia-northeast3-a \
--project=finders-487717 \
--tunnel-through-iap \
-- -L 3307:10.68.240.3:3306 -N -f์ข ๋ฃํ๋ ค๋ฉด:
# ํ๋ก์ธ์ค ์ฐพ๊ธฐ
ps aux | grep "ssh.*3307"
# ์ข
๋ฃ
kill [PID]์์ฃผ ์ฌ์ฉํ๋ค๋ฉด ~/.bashrc ๋๋ ~/.zshrc์ ์ถ๊ฐ:
alias finders-db='gcloud compute ssh finders-server --zone=asia-northeast3-a --project=finders-487717 --tunnel-through-iap -- -L 3307:10.68.240.3:3306'์ดํ finders-db ๋ช
๋ น์ด๋ก ๊ฐ๋จํ ํฐ๋ ์ด๊ธฐ!
- INFRASTRUCTURE.md - ์ธํ๋ผ ์ ๋ณด
- NETWORK_SECURITY.md - ๋คํธ์ํฌ ๋ณด์ ์ค์
- LOCAL_DEVELOPMENT.md - ๋ก์ปฌ ๊ฐ๋ฐ ํ๊ฒฝ
๋ง์ง๋ง ์ ๋ฐ์ดํธ: 2026-01-30