Google Cloud SDK 381.0.0 beta 2022.04.08 bq 2.0.74 core 2022.04.08 gsutil 5.9 Updates are available for some Google Cloud CLI components. To install them, please run: $ gcloud components update
接著登入帳號,此時會跳出登入頁填寫輸入帳號密碼
1 2 3 4 5
$ gcloud auth login
You are now logged in as [xxx@gmail.com]. Your current project is [storied-deck-xxx]. You can change this setting by running: $ gcloud config set project PROJECT_ID
這邊也可以看到在本機上登入過的帳號
1 2 3 4 5 6 7 8 9
$ gcloud auth list
Credentialed Accounts ACTIVE ACCOUNT abc@gmail.com * xxx@gmail.com
To set the active account, run: $ gcloud config set account `ACCOUNT`
再來設定專案
1 2 3
$ gcloud config set project <PROJECT_ID>
Updated property [core/project].
還有時區
1 2 3
$ gcloud config set compute/zone <ZONE_NAME>
Updated property [compute/zone].
最後則是地區
1 2 3
gcloud config set compute/region <REGION_NAME>
Updated property [compute/region].
完成後可以透過configurations查看目前的配置
1
$ gcloud config configurations list
Gcloud
只要完成上述的設定,就可以很輕鬆的使用Cloud SDK連線至資料庫,並且是SSL!
1 2 3 4 5
$ gcloud sql connect <INSTANCE_ID> --user=root
Allowlisting your IP for incoming connection for 5 minutes...
Connecting to database with SQL user [root].Enter password:
GCP會先將你的IP加入白名單後詢問密碼即可登入
接著馬上就可以看到熟悉的MySQL Command Line
1 2 3 4 5 6 7 8 9 10 11 12 13
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3773 Server version: 8.0.26-google (Google)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.