Skip to content

Instantly share code, notes, and snippets.

@whylom
Created March 8, 2012 14:49
Show Gist options
  • Save whylom/2001348 to your computer and use it in GitHub Desktop.
Save whylom/2001348 to your computer and use it in GitHub Desktop.
Open an SSH tunnel to a remote MySQL server
# Open an SSH tunnel to port 3306 (default MySQL port) on a remote machine.
# Specify the local port with an optional 2nd argument.
# The default is 3307, in case you have MySQL running locally on 3306.
#
# $ tunnel user@host
# -> opens tunnel to host on port 3306, using local port 3307
#
# $ tunnel user@host 3333
# -> opens tunnel to host on port 3306, using local port 3333
function tunnel {
port=${2-3307}
ssh $1 -L $port:localhost:3306
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment