【问题标题】:php MySql connectivity errorphp MySql 连接错误
【发布时间】:2014-07-07 04:05:00
【问题描述】:

我有以下 php 代码可以连接到我的 mysql 数据库。

mysql_connect( "myserver.com" , "root", "redhat","datastore") or die(mysql_error()); 

当我运行此代码时,我收到错误消息:

Warning: mysql_connect(): Host '10.21.21.10' is not allowed to connect to this MySQL server in C:\xampp\htdocs\inventory\net.php on line 20
Host '10.21.21.10' is not allowed to connect to this MySQL server

但是当我在命令提示符中 ping myserver.com 时,myserver.com 的 IP 为 10.25.15.95

,所以我将代码修改为:

mysql_connect( "10.21.21.10" , "root", "redhat","datastore") or die(mysql_error()); 

同样的错误重复了。

然后我将代码更改为:

mysql_connect( "10.25.15.95" , "root", "redhat","datastore") or die(mysql_error()); 

错误是

Warning: mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\inventory\net.php on line 20
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. 

请帮我解决这个问题..

提前谢谢...

【问题讨论】:

  • 您的远程服务器不允许您的 ip 连接。请联系您的托管服务提供商。

标签: php mysql mysql-connect


【解决方案1】:

在你的 mysql 服务器上:

mysql> use mysql;   

mysql> CREATE USER 'root'@'client_ipaddress' IDENTIFIED BY 'redhat';

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'client_ipaddress' WITH GRANT OPTION;

【讨论】:

    【解决方案2】:

    您在本地运行您的 PHP 脚本,但您的数据库服务器在外部某处(不在您的本地电脑上)。

    大多数数据库服务器都配置为不允许外部连接(这很好)。

    然后根据您本地机器的配置,传出请求也可能被防火墙阻止,...

    这就是您无法连接的原因。但你一开始就不应该这样做。

    永远不要将您的生产数据库链接到您的开发脚本。

    别这样!

    如果你不小心在本地机器上写了一个错误的 DELETE ALL 查询并且你不小心触发了它怎么办。哎呀...

    你正在使用 xampp,它有一个内置的 mysql 服务器,然后使用 localhost 作为你的主机连接到它。

    在您的本地机器上测试,将所有内容迁移到您的 myserver.com 主机

    【讨论】:

    • OP的数据库服务器在本地网络(IP范围从10开始),所以它是安全的。我们做同样的事情,因此专用网络上的多个开发人员可以共享一个开发数据库,​​而不是每次发生更改时每个人都必须更新本地数据库。
    猜你喜欢
    • 2014-12-03
    • 1970-01-01
    • 2018-12-18
    • 2015-08-11
    • 1970-01-01
    • 2017-10-30
    • 2023-03-15
    • 2015-04-23
    • 2016-06-14
    相关资源
    最近更新 更多