LoginSignup
5
5

More than 5 years have passed since last update.

ssh Tunnel

Posted at

よく忘れるトンネル掘り

コマンド

$ ssh -N -f -L <ローカルマシンの待受ポート番号>:<接続先で接続するホストアドレス>:<相手先で接続するポート番号> [<接続するユーザ名>@]<接続先アドレス>

ローカル(Local) からサーバ(Server)ホスト、sshトンネルを掘り、ローカルの8879に接続すれば、サーバの3306番を使用しているmysqlに接続する。

こうすることで、LocalでサーバのMySQLのデータをダンプすることが出来る。

+--------+            +--------+
| Local  |   Tunnel   | Server |
|   8879 ================> fn ----+
|        |            |        |  |
+--------+            |   3306 <--+
                      +--------+

mysql を使った接続使用例

$ ssh -N -f -L 8879:127.0.0.1:3306 server
$ mysql --host 127.0.0.1 --port 8879 --user root --password root?
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 784
Server version: 5.0.95 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
...
5
5
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
5
5