doushangxianq07480 2014-11-12 23:08
浏览 62
已采纳

通过PHP从GoDaddy连接到远程AWS MySQL

I'm having an issue connecting to a remote MySQL server that is hosted by Amazon Web Services. I can connect to this MySQL server from virtually any other computer, but for some reason I cannot get it to be pulled into my PHP that is hosted on GoDaddy.

Here is the PHP code:

$cxn = mysql_connect($host,$user,$passwd,$dbname)
         or die("Query died: Cannot connect.");

I've added the host name for the MySQL server into GoDaddy's CPANEL > Remote MySQL Access Hosts. I know that the variables are correct, because I've tested this on another server and everything works fine.

I've been on the phone with GoDaddy twice now, and all they've said is to try asking a forum (apart from adding the MySQL host to the Remote Access Hosts page).

I've checked the security group for the AWS MySQL and made sure that it is open to the GoDaddy's hosted IP address...

I'm just not sure what else to do! Why isn't this working on GoDaddy's server when it was working just fine on another??

MySQL v5.6 --> on AWS PHP v5.4 --> on GoDaddy

  • 写回答

1条回答 默认 最新

  • dongsi5381 2014-11-13 01:16
    关注

    Based on the the information in the question and the comments, it is clear that GoDaddy's network operations team does not allow outgoing TCP connection requests on port 3306 (that's MySQL's default port).

    That means you can't originate a connection from a program running on a GoDaddy server to a MySQL server located elsewhere. If you do, it will stall until the TCP connection timeout elapses.

    What can you do about this?

    1. Ask them to allow your outgoing 3306 traffic. (Not likely, I suspect. Their business model doesn't afford much per-customer network engineering work.)
    2. Try getting your MySQL server to listen on some other port, perhaps 8000. 8080, or another of the commonly used "alternative" http ports. Those might not be blocked. Then use

      mysql_connect("$host:$port",$user,$passwd,$dbname)

    to connect.

    You'll need to look up how to get an AWS-resident MySQL server to listen on a nonstandard port.

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?