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

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

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站