Port forward mysql on local network with SSH

From DevOps Notebook
Revision as of 12:26, 26 January 2022 by MilosZ (talk | contribs) (Created page with "Run from server you wanna access to MySQL that is on private network<br> that is not in same network as we are. <pre> $ ssh -v -4 -N -L 3307:<sql_server_private_ip>:3306 root@...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Run from server you wanna access to MySQL that is on private network
that is not in same network as we are.

$ ssh -v -4 -N -L 3307:<sql_server_private_ip>:3306 root@<remote_host>
$ mysql -h127.0.0.1 -p3307

If we wanna make connection persistent and auto reconnect:

$ autossh -M 0 -f -q  -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" \
 -L 3307:<sql_server_private_ip>:3306 root@<remote_host>