简体   繁体   English

PHP MySql未知服务器主机

[英]PHP MySql unknown server host

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). 我正在使用Webmin 1.680与MySQL 5.5.38和PHP 5.3.10运行Ubuntu 12.04.4 LTS(尽管我也使用终端进行管理)。 I am on a dynamic IP so I have been using dyndns to host a website, which has been working flawlessly. 我使用的是动态IP,因此我一直在使用dyndns来托管一个网站,该网站一直在正常运行。 I want to expand my website to access a mysql database. 我想扩展我的网站以访问mysql数据库。 I am attempting to use PHP to connect to mysql, specifically a specific database I set up using Webmin. 我正在尝试使用PHP连接到mysql,特别是我使用Webmin设置的特定数据库。 However, I keep getting the error: 但是,我不断收到错误:

"Unknown MySQL server host '127.0.0.1:3306'" “未知的MySQL服务器主机'127.0.0.1:3306'”

I have checked the mysql configuration and it is set to that IP and port. 我已经检查了mysql配置,并将其设置为该IP和端口。 I have also checked my server hosts and that IP is the local host. 我还检查了我的服务器主机,该IP是本地主机。 My router is set to forward port 3306 to my server. 我的路由器设置为将端口3306转发到我的服务器。 This happens whether I connect locally or remote. 无论是本地连接还是远程连接,都会发生这种情况。 I am connecting with the following PHP string: 我正在连接以下PHP字符串:

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

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. 我在任务中找到的解决方案不起作用...将连接字符串中的主机更改为“ localhost:3306”或我的dyndns主机名“ XYZ.dyndns.org:3306”或我的服务器本地IP-并更改mysql绑定地址以使其匹配。 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. 我是数据库新手,但是在使用PHP操作数据库方面做了大量研究,我只是无法克服此连接错误。 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. 我可以从服务器上的终端登录mysql,但是执行“显示数据库”命令不会列出我通过webmin创建的数据库,即使用户完全有权访问/控制该数据库。

I had a similar issue when I started out using mysqli. 当我开始使用mysqli时,我遇到了类似的问题。 If you need to include the port, it has its own place in mysqli_connect . 如果需要包含端口,则它在mysqli_connect具有其自己的位置。

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

should work better for you. 应该为您更好地工作。 But I believe 3306 is the default port, so you may be able to just leave it off. 但我相信3306是默认端口,因此您可以将其保留为关闭状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM