duanchuli5647 2015-04-03 06:09
浏览 137
已采纳

mysqli通过IP地址连接但不使用主机名

I do test run with mysqli on remote host, Working fine with IP address but its not working with fully qualified domain name. DNS is correctly mapped,I can browse the page using browser and ping also success

$mysqli = new mysqli("www.testdomain.com", "uname", "passwd", "database");

Any suggestions ? mysql is running on Centos 6

  • 写回答

1条回答 默认 最新

  • dongsu1951 2015-04-03 14:52
    关注

    First, unless you have a particular reason why you have to add www. before testdomain.com(for example, testdomain.com and www.testdomain.com are pointing to different address), please try again without www. in your host name.

    Try nslookup testdomain.com on the machine that hosts your php application(or write a php script and call gethostbyname), see if php can find the correct IP address from given host name.

    If the IP address you got from last step is different from the one you tried, try to troubleshoot DNS resolution problem, or edit /etc/hosts file on the machine that hosts your php application, and point testdomain.com to correct IP address. Some servers may have multiple IP addresses bind to them, but MySQL server only listens to one of them, check /etc/mysql/my.cnf on the machine hosts your MySQL server and look for bind 1.2.3.4(or other host name/IP address). In case you don't already know, MySQL server only accepts connections from localhost by default.

    If your MySQL server if configured to listen to a particular host name/IP address, try bind to 0.0.0.0 so your MySQL server allows connections from all sources. Also there could be a firewall blocking connections from other sources. Here's how to check firewall configuration on CentOS.

    If your php script can resolve testdomain.com, try using mysql command-line client to connect to your database from the machine that hosts your php applicaiton. mysql -h testdomain.com -u uname -p. The command-line client may give you more information on why the connection failed.

    I'm not sure if you're using hosted VPS services, such as Amazon EC2, or you have your own server machine, but Amazon EC2 does provide out-of-box firewall, it's called "Security Group". Login to your EC2 console, and click "Security Group" on left-hand-side panel, then you can edit your firewall settings on right-hand-side panel.

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

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?