Accessing MYSQL server behind firewall using SSH

This specific content was written 11 years ago. Please keep this in mind as it may be outdated and not adhering to best-practices.

So, you want to access a MYSQL server but you only have an SSH terminal…
Not to worry, you can use SSH tunnelling to do this!

Basic Example

Example: ssh -L 3306:localhost:3306 user@IP -p SSHPORT

Now how do you control this dark ssh sorcery? Let’s break it down.

1) 3306:localhost:3306

  •  Open a port 3306 on my local machine to redirect
  • localhost:3306 means we are tunnelling to 3306 on SSH machine

2) user@IP

This is your username and the IP address of the server

3) -p SSHPORT

This is the ssh port if it is not on 22.

Another Example

ssh -L 9000:192.168.212.1:5000 user@192.168.2.1 -p 1234

You would use this if you wanted to:

  • use your computer port 9000
  • to access the port 5000 on IP 192.168.212.1
  • through the SSH server 192.168.2.1
  • with SSH server port on 1234

Happy SSHing!

 



Menelaos Bakopoulos

Mr. Menelaos Bakopoulos is currently pursuing his PhD both at Center for TeleInFrastruktur (CTiF) at Aalborg University (AAU) in Denmark and Athens Information Technology (AIT) in Athens, Greece. He received a Master in Information Technology and Telecommunications Systems from Athens Information Technology and a B.Sc. in Computer Science & Management Information Systems from the American College of Thessaloniki. Since April 2008 he has been a member of the Multimedia, Knowledge, and Web Technologies Group.

More Posts