0
0

More than 3 years have passed since last update.

【AWS】EC2踏み台サーバー経由でプライベートサブネットのDBに接続する

Last updated at Posted at 2021-06-22

SSHトンネルが簡単

下記のコマンドでsshトンネルを作成します。

ssh ec2-user@踏み台のhostname -i pemファイルのパス -L 3306:DBのhostname:3306

今回は例としてmysql(aurora)に接続します。
別のシェルで、以下のコマンドでmysqlに接続します。
ホスト名を127.0.0.1ではなくlocalhostにすると、エラーが発生する場合があります。
(ソケット接続か、TCP接続かの問題らしい)

mysql -h 127.0.0.1 -P 3306 -u DBのユーザー名 -p

接続成功!

image.png

バックエンドの開発の際にも、127.0.0.1でDBに接続できるので便利です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0