duanci6484 2012-04-18 13:15
浏览 67
已采纳

Mysql连接到VLAN外部的外部/远程服务器

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.

  • 写回答

1条回答 默认 最新

  • duangao8359 2012-04-18 15:14
    关注

    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...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题