PHP MySql未知服务器主机 [英] PHP MySql unknown server host

查看:162
本文介绍了PHP MySql未知服务器主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Webmin 1.680(带有终端管理)运行带有MySQL 5.5.38和PHP 5.3.10的Ubuntu 12.04.4 LTS.我使用的是动态IP,因此我一直在使用dyndns来托管一个网站,该网站一直在正常运行.我想扩展我的网站以访问mysql数据库.我试图使用PHP连接到mysql,特别是我使用Webmin设置的特定数据库.但是,我不断收到错误消息:

I am running Ubuntu 12.04.4 LTS with MySQL 5.5.38 and PHP 5.3.10, using Webmin 1.680 (although I do use the terminal for administration as well). I am on a dynamic IP so I have been using dyndns to host a website, which has been working flawlessly. I want to expand my website to access a mysql database. I am attempting to use PHP to connect to mysql, specifically a specific database I set up using Webmin. However, I keep getting the error:

未知的MySQL服务器主机'127.0.0.1:3306'"

"Unknown MySQL server host '127.0.0.1:3306'"

我已经检查了mysql配置,并将其设置为该IP和端口.我还检查了我的服务器主机,并且该IP是本地主机.我的路由器设置为将端口3306转发到我的服务器.无论是本地连接还是远程连接,都会发生这种情况.我正在连接以下PHP字符串:

I have checked the mysql configuration and it is set to that IP and port. I have also checked my server hosts and that IP is the local host. My router is set to forward port 3306 to my server. This happens whether I connect locally or remote. I am connecting with the following PHP string:

$link = mysqli_connect("127.0.0.1:3306", "username", "password", "dbname");

我在任务中找到的解决方案不起作用...将连接字符串中的主机更改为"localhost:3306"或我的dyndns主机名"XYZ.dyndns.org:3306",或我服务器的本地IP-并更改mysql绑定地址以使其匹配.我尝试注释掉配置文件中的绑定地址.我在该论坛和其他论坛上发现了类似的问题,但没有一个对我有用的解决方案.我是数据库新手,但是在使用PHP操作数据库方面进行了大量研究,我无法克服此连接错误.我一直在自学如何运行服务器,并能够自己解决所有问题,直到解决这个问题为止.我可以从服务器上的终端登录mysql,但是执行显示数据库"命令不会列出我通过webmin创建的数据库,即使用户可以完全访问/控制该数据库.

The solutions I have found in my quest, which do not work... changing the host in the connection string to "localhost:3306" or to my dyndns host name "XYZ.dyndns.org:3306", or to my server's local IP - and changing the mysql binding address to match. I have tried commenting out the binding address in the config file. I have found similar questions asked on this forum and others but none have a solution that works for me. I am new to databases but have done a lot of research on using PHP to manipulate them, I just can't get past this connection error. I have been self-teaching how to run a server and have been able to figure out every problem myself up until this one. I can log into mysql from the terminal on my server but executing the "show databases" command it doesn't list the database I created through webmin, even though I the user to have full access/control of that database.

推荐答案

当我开始使用mysqli时,我遇到了类似的问题.如果需要包括端口,则它在mysqli_connect中具有自己的位置.

I had a similar issue when I started out using mysqli. If you need to include the port, it has its own place in mysqli_connect.

$link = mysqli_connect("127.0.0.1", "username", "password", "dbname", 3306);

应该为您更好地工作.但我相信3306是默认端口,因此您可以将其保留为关闭状态.

should work better for you. But I believe 3306 is the default port, so you may be able to just leave it off.

这篇关于PHP MySql未知服务器主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆