0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ローカルのMySQLクライアント使って踏み台の先のMySQLにアクセスする方法

Last updated at Posted at 2021-12-17

初回準備

  1. 踏み台サーバにアクセス元(ローカル)の公開鍵を登録
  2. ローカルのSSH Configに以下を追加
~/.ssh/config
Host 踏み台の名前
  HostName       例えばEC2のホスト名
  User           ec2-userみたいなの

MySQLへのアクセス

1.接続準備

接続用のポートを開く

ssh -fNL 23306:接続先MySQLのホスト名:接続先MySQLのポート 踏み台の名前

2.接続

ローカルのMySQLクライアントを使ってDBにアクセス

mysql -u 接続先MySQLのユーザ名 -p -h 127.0.0.1 -P 23306 DB名

or

mycli mysql://接続先MySQLのユーザ名@127.0.0.1:23306/DB名

3.後始末

開いたポートを閉じておく

ps aux | grep '[0-9] ssh -fNL 23306' | awk '{print "kill -9", $2}' | sh

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?