Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

and thank you for your help so far.

Here is my problem:

I have two remote dedicated servers, one webserver that runs apache, and one db server that runs mysql.

The apache server is visible on the internet of course, but the second server is only visible to the apache server because they are connected with LAN.

I need to connect to the remote mysql server through internet from my home-pc , but only apache server is visible to my home-pc. How can i setup port-forwarding from my apache server to the mysql server so i will be able to "see" the mysql server from my home-pc?

This question is a follow-up from my first question Connect to remote mysql server from my application. Problem is that Mysql server is on LAN in which you answered me and helped me a lot by telling me to do "port-forwarding".

I looked over the internet, and i cant find a good how-to to do port-forwarding. I'm an experienced programmer, but have little experience on hardware and networks. I can understand though what must be done, so i just need a litle help to sort things out :)

I hope you can help me guys, Thank you in advance

p.s. machine that Apache is running is on CentOS, mysql server also CentOS. p.s2 webserver runs WebHostManager i dont know if that makes any difference or it can be made easily through this, i just mention it :)

share|improve this question

migrated from Dec 4 '10 at 1:10

This question came from our site for professional and enthusiast programmers.

This should be asked on serverfault – rwilliams aka r-dub Dec 2 '10 at 10:27
How do you intend to connect to your mysql server? Web? Navicat? Command line? – andreas Dec 2 '10 at 10:29

Fire up your SSH client on your desktop.

Type this in (stuff below explains what you are replacing):

ssh -L desktop_port:database_host:database_port apache_username@apache_host

  • desktop_port: 3306 (only use this if you aren't running mysql locally)
  • database_host: your database host (use domain name or ip address)
  • database_port: 3306 (change if you aren't using the default port)
  • apache_username: the username used to login to your apache server
  • apache_host: the apache host (the domain name or ip address)

When prompted, enter your apache_username's password. Keep this terminal open as the tunnel will close when you close this connection.

An example that works for me:

ssh -L 3306:db:3306 user@web

When you are all done, just type exit on your terminal and the connection will be gone.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.