
私
Google Cloud Platform で DBインスタンスを作成し、自マシンからアクセスするには?
コンテンツ
データベースインスタンスの作成
好きなデータベースを選択
現在は MySQL、PostgreSQL、SQL Server の三つから選ぶことが可能。
今回はポスグレを使うよ

情報の入力
インスタンスIDやアドミンパスワード等、必要な情報を入力。

Public IP アドレスを確認
作成が完了したら、IPアドレスを確認しておこう。
インスタンスの作成が完了するまで数分かかるよ

ネットワークの設定
自マシンから接続するために、事前に自マシンの外部IPアドレスを登録しておこう。
外部からの接続を許可したいIPアドレスの登録はこちらから


gcloud CLI を自マシンにインストール
インストール
以下のリンクからファイルをダウンロードし、展開してから install.sh を実行する。
-
-
Install the gcloud CLI | Google Cloud CLI Documentation
cloud.google.com
初期設定
gcloud init でタイムゾーンの設定や、ログインの確認などの初期設定をする。
実行例
hellomyworld@MacBook-Air ~ % gcloud init
Welcome! This command will take you through the configuration of gcloud.
Your current configuration has been set to: [default]
You can skip diagnostics next time by using the following flag:
gcloud init --skip-diagnostics
Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).
You must log in to continue. Would you like to log in (Y/n)?
Your browser has been opened to visit:
接続確認
先ほど作成したデータベースに接続することができることを確認。
gcloud sql connect <インスタンス名> --user=postgres
実行例
hellomyworld@MacBook-Air ~ % gcloud sql connect test --user=postgres
Allowlisting your IP for incoming connection for 5 minutes...⠶
Allowlisting your IP for incoming connection for 5 minutes...done.
Connecting to database with SQL user [postgres].Password: