Closed10
ローカルから CloudSQL に接続する
![薄田達哉 / tatsuyasusukida](https://res.cloudinary.com/zenn/image/fetch/s--h04js5hX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/02d3bdd44b.jpeg)
このスクラップについて
ローカルでプロキシサーバーを起動して CloudSQL に接続できるようにする手順をまとめる。
![薄田達哉 / tatsuyasusukida](https://res.cloudinary.com/zenn/image/fetch/s--h04js5hX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/02d3bdd44b.jpeg)
過去にやったことがある
ここから漁ろう。
![薄田達哉 / tatsuyasusukida](https://res.cloudinary.com/zenn/image/fetch/s--h04js5hX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/02d3bdd44b.jpeg)
こっちだった
![薄田達哉 / tatsuyasusukida](https://res.cloudinary.com/zenn/image/fetch/s--h04js5hX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/02d3bdd44b.jpeg)
関連ドキュメント
![薄田達哉 / tatsuyasusukida](https://res.cloudinary.com/zenn/image/fetch/s--h04js5hX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/02d3bdd44b.jpeg)
インスタンスを探す
コマンド
# 現在のプロジェクトを確認
gcloud config get-value project
# プロジェクトの一覧
gcloud config configurations list
# プロジェクトの切り替え
gcloud config configurations activate xxxx
# インスタンス一覧
gcloud sql instances list
# 接続名の表示
gcloud sql instances describe yyyy | grep connectionName
![薄田達哉 / tatsuyasusukida](https://res.cloudinary.com/zenn/image/fetch/s--h04js5hX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/02d3bdd44b.jpeg)
プロキシ?プロクシ?
ドキュメントではプロキシだったのでこちらに統一する。
![薄田達哉 / tatsuyasusukida](https://res.cloudinary.com/zenn/image/fetch/s--h04js5hX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/02d3bdd44b.jpeg)
プロキシサーバー起動
コマンド
cloud-sql-proxy --address 0.0.0.0 --port 13306 xxxx:yyyy:zzzz
![薄田達哉 / tatsuyasusukida](https://res.cloudinary.com/zenn/image/fetch/s--h04js5hX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/02d3bdd44b.jpeg)
別ターミナル起動
コマンド
mysql -u root -p -h 127.0.0.1 -P 13306
![薄田達哉 / tatsuyasusukida](https://res.cloudinary.com/zenn/image/fetch/s--h04js5hX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/02d3bdd44b.jpeg)
おわりに
はじめての場合はインストールや初期設定が必要となる。
詳しくは下記の投稿をご覧ください。
このスクラップは2023/08/04にクローズされました