MySQL over SSH tunnel

Posted: October 19, 2010 in MySQL, Shell scripting
Tags: , , , ,

Sometimes we face a problem when we have SSH access to the server, but not to MySQL.
Here is a simple workaround – SSH tunnel:

ssh -f -N -L LOCAL_PORT:127.0.0.1:3306 USER@HOST

This command allows you to map remote port to the local one via SSH tunnel.

  • LOCAL_PORT – local port to map to
  • USER – SSH username
  • HOST – remote host

Surely, you can map other ports as well.

When you mapped the port, you can connect to MySQL using your favorite client (you need to specify LOCAL_PORT as MySQL server port in connection settings).

Advertisements
Comments
  1. KosMax says:

    Hi, thanks a lot for this code. It`s work for me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s