forked from lavishsheth/code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Implementing Cloud SQL
35 lines (25 loc) · 1.43 KB
/
Implementing Cloud SQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
ZONE=$(gcloud compute instances list --filter="name=wordpress-proxy" --format "get(zone)" | awk -F/ '{print $NF}')
REGION=${ZONE::-2}
gcloud services enable servicenetworking.googleapis.com
gcloud services enable servicemanagement.googleapis.com
export PROJECT_ID=$(gcloud config list --format 'value(core.project)')
gcloud compute addresses create default-ip-rangeee \
--global \
--purpose=VPC_PEERING \
--prefix-length=24 \
--description="SQL" \
--network=default
gcloud services vpc-peerings connect \
--service=servicenetworking.googleapis.com \
--ranges=default-ip-rangeee \
--network=default
gcloud beta sql instances create wordpress-db --database-version=MYSQL_5_7 --cpu=1 --memory=3840MB --region=$REGION --root-password=password123 --network=projects/$PROJECT_ID/global/networks/default --allocated-ip-range-name=default-ip-rangeee
gcloud sql databases create wordpress --instance=wordpress-db
gcloud beta compute ssh wordpress-proxy -- -vvv
#---------SSH------------------
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy && chmod +x cloud_sql_proxy
export PROJECT_ID=$(gcloud config list --format 'value(core.project)')
ZONE=$(gcloud compute instances list --filter="name=wordpress-proxy" --format "get(zone)" | awk -F/ '{print $NF}')
REGION=${ZONE::-2}
export SQL_CONNECTION=$PROJECT_ID:$REGION:wordpress-db
./cloud_sql_proxy -instances=$SQL_CONNECTION=tcp:3306 &