Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ์ฌ์ฉํ์ฌ MySQL์ฉ Cloud SQL์ ์ฐ๊ฒฐ
์ด ํ์ด์ง์์๋ Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ์ฌ์ฉํ์ฌ ๋ก์ปฌ ํ ์คํธ ํ๊ฒฝ์์ Cloud SQL์ ์ฐ๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค. Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ์ฌ์ฉํ๋ฉด ์น์ธ๋ ๋คํธ์ํฌ๋ SSL ๊ตฌ์ฑ ์์ด๋ Cloud SQL ์ธ์คํด์ค์ ์์ ํ๊ฒ ์ก์ธ์คํ ์ ์์ต๋๋ค. Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ์ฌ์ฉํ๋ฉด Cloud SQL ์ธ์คํด์ค์ ์์ ํ๊ฒ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค.
์ด ํ์ด์ง์ ์๋ด๋ ํ ์คํธ ํ๊ฒฝ ์ ์ฉ์ด๋ฉฐ ํ๋ก๋์ ํ๊ฒฝ์ ์ฌ์ฉ๋์ด์๋ ์ ๋ฉ๋๋ค. ํ๋ก๋์ ํ๊ฒฝ์ ํ์ํ ๊ตฌ์ฑ์ ๋ํ ์์ธํ ๋ด์ฉ์ ํ๋ก๋์ ํ๊ฒฝ์์ Cloud SQL ์ธ์ฆ ํ๋ก์ ์ฌ์ฉ ๋ฐ Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ์ฌ์ฉํ์ฌ ์ฐ๊ฒฐ์ ์ฐธ์กฐํ์ธ์.
์์ํ๊ธฐ ์ ์
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
ํ์ํ Google Cloud API๋ฅผ ์ฌ์ฉ ์ค์ ํฉ๋๋ค.
์ฝ์
Google Cloud ์ฝ์์์ API ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
Cloud SQL Admin API๋ฅผ ์ฌ์ฉ ์ค์ ํฉ๋๋ค.gcloud
๋ค์ ๋ฒํผ์ ํด๋ฆญํ์ฌ ๋ธ๋ผ์ฐ์ ์์ ์ง์ Google Cloud ๋ฆฌ์์ค์ ๋ํด ๋ช ๋ น์ค ์ก์ธ์ค๋ฅผ ์ ๊ณตํ๋ Cloud Shell์ ์ฝ๋๋ค. Cloud Shell์ ์ฌ์ฉํ์ฌ ์ด ๋น ๋ฅธ ์์ ์ ์ฒด์ ํ์๋
gcloud
๋ช ๋ น์ด๋ฅผ ์คํํ ์ ์์ต๋๋ค.Cloud Shell์ ์ฌ์ฉํ์ฌ ๋ค์๊ณผ ๊ฐ์ด
gcloud services enable
๋ช ๋ น์ด๋ฅผ ์คํํด ์ด ๋น ๋ฅธ ์์์ ํ์ํ API๋ฅผ ์ฌ์ฉ ์ค์ ํฉ๋๋ค.gcloud services enable sqladmin.googleapis.com
์ด ๋ช ๋ น์ด๋ ๋ค์ API๋ฅผ ์ฌ์ฉ ์ค์ ํฉ๋๋ค.
- Cloud SQL Admin API
-
Make sure that you have the following role or roles on the project: Cloud SQL Admin (
roles/cloudsql.admin
), Cloud SQL Viewer (roles/cloudsql.viewer
)Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
IAM์ผ๋ก ์ด๋ - ํ๋ก์ ํธ๋ฅผ ์ ํํฉ๋๋ค.
- ์ก์ธ์ค ๊ถํ ๋ถ์ฌ๋ฅผ ํด๋ฆญํฉ๋๋ค.
-
์ ์ฃผ ๊ตฌ์ฑ์ ํ๋์ ์ฌ์ฉ์ ์๋ณ์๋ฅผ ์ ๋ ฅํฉ๋๋ค. ์ผ๋ฐ์ ์ผ๋ก Google ๊ณ์ ์ ์ด๋ฉ์ผ ์ฃผ์์ ๋๋ค.
- ์ญํ ์ ํ ๋ชฉ๋ก์์ ์ญํ ์ ์ ํํฉ๋๋ค.
- ์ญํ ์ ์ถ๊ฐ๋ก ๋ถ์ฌํ๋ ค๋ฉด ๋ค๋ฅธ ์ญํ ์ถ๊ฐ๋ฅผ ํด๋ฆญํ๊ณ ๊ฐ ์ญํ ์ ์ถ๊ฐํฉ๋๋ค.
- ์ ์ฅ์ ํด๋ฆญํฉ๋๋ค.
-
Cloud SQL ์ธ์คํด์ค ๋ง๋ค๊ธฐ
์ด ๋น ๋ฅธ ์์์์๋ Google Cloud ์ฝ์์ ์ฌ์ฉํฉ๋๋ค. gcloud CLI, cURL ๋๋ PowerShell์ ์ฌ์ฉํ๋ ค๋ฉด ์ธ์คํด์ค ๋ง๋ค๊ธฐ๋ฅผ ์ฐธ์กฐํ์ธ์.
-
Google Cloud ์ฝ์์์ Cloud SQL ์ธ์คํด์ค ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
- ์ธ์คํด์ค ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
- MySQL ์ ํ์ ํด๋ฆญํฉ๋๋ค.
- ์ธ์คํด์ค ID ํ๋์
myinstance
๋ฅผ ์ ๋ ฅํฉ๋๋ค. - ๋น๋ฐ๋ฒํธ ํ๋์
root
์ฌ์ฉ์์ ๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅํฉ๋๋ค. ์ธ์คํด์ค ๋ง๋ค๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
์ธ์คํด์ค ๋ชฉ๋ก์ผ๋ก ๋์๊ฐ๋๋ค. ์ ์ธ์คํด์ค๋ฅผ ๋ฐ๋ก ํด๋ฆญํ๋ฉด ์ธ๋ถ์ ๋ณด๋ฅผ ๋ณผ ์ ์์ง๋ง ์ด๊ธฐํ ๋ฐ ์์ ์ ์๋ ๋ค๋ฅธ ์์ ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
- MySQL Community Server ๋ค์ด๋ก๋ ํ์ด์ง์์ ํ๋ซํผ์ ๋ง๋ MySQL Community Server๋ฅผ ๋ค์ด๋ก๋ํฉ๋๋ค.
Community Server์ MySQL ํด๋ผ์ด์ธํธ๊ฐ ํฌํจ๋์ด ์์ต๋๋ค. - ๋ค์ด๋ก๋ ํ์ด์ง์ ์ง์์ ๋ฐ๋ผ Community Server๋ฅผ ์ค์นํฉ๋๋ค.
MySQL์ ์ค์นํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์์ธํ ๋ด์ฉ์ MySQL ์ค์น ๋ฐ ์ ๊ทธ๋ ์ด๋๋ฅผ ์ฐธ์กฐํ์ธ์.
Cloud SQL ์ธ์ฆ ํ๋ก์ ํด๋ผ์ด์ธํธ ์ค์น
์ฌ์ฉ ์ค์ธ ์ด์์ฒด์ ๋ฐ ์ด์์ฒด์ ๊ฐ ์ฌ์ฉํ๋ ์ปค๋(32๋นํธ ๋๋ 64๋นํธ)์ ๋ฐ๋ผ ๋ค๋ฅธ Cloud SQL ์ธ์ฆ ํ๋ก์ ๋ฐ์ด๋๋ฆฌ๋ฅผ ๋ค์ด๋ก๋ํฉ๋๋ค.
๋๋ถ๋ถ์ ์ต์ ํ๋์จ์ด๋ 64๋นํธ ์ปค๋์ ์ฌ์ฉํฉ๋๋ค. ๋จธ์ ์์ 32๋นํธ ์ปค๋์ ์คํ ์ค์ธ์ง ๋๋ 64๋นํธ ์ปค๋์ ์คํ ์ค์ธ์ง ํ์คํ์ง ์์ ๊ฒฝ์ฐ Linux ๋๋ macOS์์ uname -a
๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํฉ๋๋ค. Windows์ ๊ฒฝ์ฐ Windows ๋ฌธ์๋ฅผ ์ฐธ์กฐํ์ธ์.
Linux 64๋นํธ
- Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ๋ค์ด๋ก๋ํฉ๋๋ค.
curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.18.0/cloud-sql-proxy.linux.amd64
- Cloud SQL ์ธ์ฆ ํ๋ก์ ์คํ ํ์ผ์ ๋ง๋ญ๋๋ค.
chmod +x cloud-sql-proxy
Linux 32๋นํธ
- Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ๋ค์ด๋ก๋ํฉ๋๋ค.
curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.18.0/cloud-sql-proxy.linux.386
curl
๋ช ๋ น์ด๋ฅผ ์ฐพ์ ์ ์์ผ๋ฉดsudo apt install curl
์ ์คํํ๊ณ ๋ค์ด๋ก๋ ๋ช ๋ น์ด๋ฅผ ๋ฐ๋ณตํฉ๋๋ค.- Cloud SQL ์ธ์ฆ ํ๋ก์ ์คํ ํ์ผ์ ๋ง๋ญ๋๋ค.
chmod +x cloud-sql-proxy
macOS 64๋นํธ
- Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ๋ค์ด๋ก๋ํฉ๋๋ค.
curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.18.0/cloud-sql-proxy.darwin.amd64
- Cloud SQL ์ธ์ฆ ํ๋ก์ ์คํ ํ์ผ์ ๋ง๋ญ๋๋ค.
chmod +x cloud-sql-proxy
Mac M1
- Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ๋ค์ด๋ก๋ํฉ๋๋ค.
curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.18.0/cloud-sql-proxy.darwin.arm64
- Cloud SQL ์ธ์ฆ ํ๋ก์ ์คํ ํ์ผ์ ๋ง๋ญ๋๋ค.
chmod +x cloud-sql-proxy
Windows 64๋นํธ
https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.18.0/cloud-sql-proxy.x64.exe๋ฅผ ๋ง์ฐ์ค ์ค๋ฅธ์ชฝ ๋ฒํผ์ผ๋ก ํด๋ฆญํ๊ณ ๋ค๋ฅธ ์ด๋ฆ์ผ๋ก ๋งํฌ ์ ์ฅ์ ์ ํํ์ฌ Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ๋ค์ด๋ก๋ํฉ๋๋ค. ํ์ผ ์ด๋ฆ์cloud-sql-proxy.exe
๋ก ๋ฐ๊ฟ๋๋ค.
Windows 32๋นํธ
https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.18.0/cloud-sql-proxy.x86.exe๋ฅผ ๋ง์ฐ์ค ์ค๋ฅธ์ชฝ ๋ฒํผ์ผ๋ก ํด๋ฆญํ๊ณ ๋ค๋ฅธ ์ด๋ฆ์ผ๋ก ๋งํฌ ์ ์ฅ์ ์ ํํ์ฌ Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ๋ค์ด๋ก๋ํฉ๋๋ค. ํ์ผ ์ด๋ฆ์cloud-sql-proxy.exe
๋ก ๋ฐ๊ฟ๋๋ค.
Cloud SQL ์ธ์ฆ ํ๋ก์ Docker ์ด๋ฏธ์ง
Cloud SQL ์ธ์ฆ ํ๋ก์์๋ distroless
, alpine
, buster
์ ๊ฐ์ ์๋ก ๋ค๋ฅธ ์ปจํ
์ด๋ ์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค. ๊ธฐ๋ณธ Cloud SQL ์ธ์ฆ ํ๋ก์ ์ปจํ
์ด๋ ์ด๋ฏธ์ง๋ ์
ธ์ด ์๋ distroless
๋ฅผ ์ฌ์ฉํฉ๋๋ค. ์
ธ ๋๋ ๊ด๋ จ ๋๊ตฌ๊ฐ ํ์ํ๋ฉด alpine
๋๋ buster
๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋ํฉ๋๋ค.
์์ธํ ๋ด์ฉ์ Cloud SQL ์ธ์ฆ ํ๋ก์ ์ปจํ
์ด๋ ์ด๋ฏธ์ง๋ฅผ ์ฐธ์กฐํ์ธ์.
๋ค์ ๋ช ๋ น์ด๋ก Docker๋ฅผ ์ฌ์ฉํ์ฌ ์ต์ ์ด๋ฏธ์ง๋ฅผ ๋ก์ปฌ ๋จธ์ ์ผ๋ก ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.
docker pull gcr.io/cloud-sql-connectors/cloud-sql-proxy:2.18.0
๊ธฐํ OS
์ฌ๊ธฐ์ ํฌํจ๋์ง ์์ ๋ค๋ฅธ ์ด์์ฒด์ ์ ๊ฒฝ์ฐ ์์ค์์ Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ์ปดํ์ผํ๋ฉด ๋ฉ๋๋ค.์ธ์คํด์ค ์ฐ๊ฒฐ ์ด๋ฆ ํ์ธ
-
Google Cloud ์ฝ์์์ Cloud SQL ์ธ์คํด์ค ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
- ์ธ์คํด์ค ์ด๋ฆ์ ํด๋ฆญํ์ฌ ๊ฐ์ ํ์ด์ง๋ฅผ ์ฝ๋๋ค.
- ์ด ์ธ์คํด์ค์ ์ฐ๊ฒฐ ์น์
์์ ์ฐ๊ฒฐ ์ด๋ฆ์ ๋ณต์ฌํฉ๋๋ค. ์ฐ๊ฒฐ ์ด๋ฆ์
projectID:region:instanceID
ํ์์ ๋๋ค.
Cloud SQL ์ธ์ฆ ํ๋ก์ ์์
์ถ๋ ฅ์ ๋ชจ๋ํฐ๋งํ ์ ์๋๋ก ์์ฒด ํฐ๋ฏธ๋์์ Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ์์ํฉ๋๋ค. INSTANCE_CONNECTION_NAME
์ ์ด์ ๋จ๊ณ์์ ๋ณต์ฌํ ์ธ์คํด์ค ์ฐ๊ฒฐ ์ด๋ฆ์ผ๋ก ๋ฐ๊ฟ๋๋ค.
Linux ํ๊ฒฝ์ ๊ฒฝ์ฐ ๋ค์ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ์์ํฉ๋๋ค.
./cloud-sql-proxy INSTANCE_CONNECTION_NAME
Windows์ PowerShell์์๋ ๋ค์ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ์์ํฉ๋๋ค.
.\cloud-sql-proxy.exe INSTANCE_CONNECTION_NAME
๋ค์๊ณผ ์ ์ฌํ ๋ฉ์์ง๊ฐ ๋ํ๋ฉ๋๋ค.
Listening on 127.0.0.1:3306 for INSTANCE_CONNECTION_NAME Ready for new connections
๋ค์ ๋ช ๋ น์ด๋ฅผ ์คํํฉ๋๋ค.
mysql -u root -p --host 127.0.0.1 --port 3306
Enter password:
ํ๋กฌํํธ์์ MySQL ๋ฃจํธ ์ฌ์ฉ์ ๊ณ์ ์ ๋น๋ฐ๋ฒํธ๋ฅผ ์
๋ ฅํฉ๋๋ค.
MySQL ํ๋กฌํํธ๊ฐ ํ์๋๋์ง ํ์ธํฉ๋๋ค. mysql ํด๋ผ์ด์ธํธ๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ฐ๊ฒฐํ์ต๋๋ค.
Cloud SQL ์ธ์ฆ ํ๋ก์๋ฅผ ์์ํ ํฐ๋ฏธ๋ ์ฐฝ์ผ๋ก ๋์๊ฐ๋๋ค. ๋ค์๊ณผ ์ ์ฌํ ๋ฉ์์ง๊ฐ ํ์๋ฉ๋๋ค.
New connection for myInstance
์ญ์
์ด ํ์ด์ง์์ ์ฌ์ฉํ ๋ฆฌ์์ค ๋น์ฉ์ด Google Cloud ๊ณ์ ์ ์ฒญ๊ตฌ๋์ง ์๋๋ก ํ๋ ค๋ฉด ๋ค์ ๋จ๊ณ๋ฅผ ์ํํฉ๋๋ค.
-
Google Cloud ์ฝ์์์ Cloud SQL ์ธ์คํด์ค ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
myinstance
์ธ์คํด์ค๋ฅผ ์ ํํ์ฌ ์ธ์คํด์ค ์ธ๋ถ์ ๋ณด ํ์ด์ง๋ฅผ ์ฝ๋๋ค.- ํ์ด์ง ์๋จ์ ์์ด์ฝ ํ์์ค์์ ์ญ์ ๋ฅผ ํด๋ฆญํฉ๋๋ค.
- ์ธ์คํด์ค ์ญ์ ์ฐฝ์์ ์ธ์คํด์ค ์ด๋ฆ์ ์ ๋ ฅํ ํ ์ญ์ ๋ฅผ ํด๋ฆญํฉ๋๋ค.
์ ํ์ ์ธ ์ญ์ ๋จ๊ณ
์ด ๋น ๋ฅธ ์์์ ์งํํ๋ ๋์ ์ฌ์ฉ ์ค์ ๋ API๋ฅผ ์ฌ์ฉํ์ง ์์ ๋๋ ์ด๋ฅผ ์ฌ์ฉ ์ค์งํ ์ ์์ต๋๋ค.
- ์ด ๋น ๋ฅธ ์์ ๋ด์์ ์ฌ์ฉ ์ค์ ๋ API:
- Cloud SQL Admin API
Google Cloud ์ฝ์์์ API ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
Cloud SQL Admin API๋ฅผ ์ ํํ ํ API ์ฌ์ฉ ์ค์ง ๋ฒํผ์ ํด๋ฆญํฉ๋๋ค.
๋ค์ ๋จ๊ณ
Cloud SQL ์ธ์ฆ ํ๋ก์ ์ ๋ณด ๋ฌธ์ ํด๊ฒฐ ๋ฐฉ๋ฒ ์์๋ณด๊ธฐ
Cloud SQL ์ธ์ฆ ํ๋ก์ ์์ธํ ์์๋ณด๊ธฐ
- ๊ธฐํ ์ฐ๊ฒฐ ์ต์ ์์ธํ ์์๋ณด๊ธฐ