I am trying to connect to an external mysql server from a computer which is inside a vlan where my application will run. The remote server is not a member of the vlan. The following is what I have tried so far.
Mysql Port forwarding from my vlan server
ssh -L 3306:my-vlan-server-ip:3306 user-at-external-server@external-server-ip
In this case I get a ssh timeout message. Tried to do it directly from my php mysql_connect I get mysql error #111 yet I have already edited the my.cnf as:
#skip-networking
bind-address =my-vlan-server-ip
My php db connect script
<?php
$conn=mysql_connect("external-server-ip","user","pass");
if($conn)
{
echo "success";
}
else
{
echo "fail";
}
?>
Kindly someone help.Let me know where I am going wrong. Thanks.
If I understand you correctly you are running the ssh client on the vlan server (=my-vlan-server-ip)?
The local tunnelling (-L) basicly forwards the first port to the given port on the given address, i.e -L 80:someserver:8080 forwards port 80 on the local machine to port 8080 on someserver... so if you want to connect to 3306 on the remote server via ssh you do:
ssh -L 3306:external-server-ip:3306 user-at-external-server@external-server-ip (or just -L 3306:localhost:3306, localhost will then refer to the server to which you are connecting, ie external-server-ip)
localhost:3306 is then forwarded to external-server-ip:3306
in the php script running on my-vlan-server-ip you then connect to localhost:3306, which is then forwarded to external-server-ip by ssh...