Mysqli连接到完全不同的IP

时间:2016-02-15 12:19:21

标签: php mysql mysqli

我尝试通过mysqli_connect oop版本连接到我的服务器(ip 5.39.6 *。**)(也是经过测试的程序版本),它总是给我这个错误信息:

拒绝访问用户'****'@'62.214.6*.***'(使用密码:是)

我的问题是错误消息中的IP总是与尝试连接的IP无法匹配。我不知道为什么

目前已审查的用户和IP。如果我连接heidisql(programm like navicat)一切正常。只有我安装的本地apache 2.4(php 5.5)无法连接到它

Traceroute看起来像这样:

  1     1 ms     1 ms     1 ms  (censored)
  2    <1 ms    <1 ms    <1 ms  192.168.130.250
  3     2 ms     1 ms     1 ms  (censored)
  4   202 ms     6 ms   205 ms  (censored)
  5     5 ms     4 ms     4 ms  (censored)
  6     5 ms     5 ms     5 ms  (censored)
  7     *        *        *     Zeitüberschreitung der Anforderung.
  8    19 ms    18 ms    18 ms  rbx-g1-a9.fr.eu [94.23.122.76]
  9    19 ms    19 ms    19 ms  vac1-0-a9.fr.eu [178.33.100.149]
 10    21 ms    32 ms    28 ms  vac1-1-n7.fr.eu.firewall [178.33.100.152]
 11    20 ms    21 ms    18 ms  vac1-2-n7.fr.eu.tilera [37.187.36.245]
 12    19 ms    18 ms    18 ms  vac1-3-n7.fr.eu [91.121.215.13]
 13     *        *        *     Zeitüberschreitung der Anforderung.
 14    18 ms    18 ms    18 ms  5.39.6*.**

代码:

    $this->_mysqli = new \MySQLi($this->host, $this->username, $this->password, $this->db, $this->port);

host:target ip(5.39.6 *。**) 用户&amp; pw:显然是私人的 db:数据库名称,确实存在于服务器上 港口:3306

错误:

Access denied for user '*****'@'62.214.6*.***' (using password: YES)

1 个答案:

答案 0 :(得分:2)

mysql权限适用于&#34;三胞胎&#34; 你有一个&#34;用户&#34;,你有一个&#34;密码&#34;而且你有一个&#34;起源&#34;。

在这种情况下,用户和密码非常明显,origin代表启动与mysql服务器连接的ip,在你的情况下62.214.6x.xxx就像你的traceroute表示代表你的互联网连接的公共ip。 / p>

您必须检查服务器上的权限以匹配此三元组,才能执行

select * from information_schema.user_privileges 
  where GRANTEE like '%YOUR_USER%' group by grantee;

您会看到类似

的内容
+-------------------------------------+---------------+----------------+--------------+
| GRANTEE                             | TABLE_CATALOG | PRIVILEGE_TYPE | IS_GRANTABLE |
+-------------------------------------+---------------+----------------+--------------+
| 'YOUR_USER'@'127.0.0.1'             | def           | SELECT         | YES          |
| 'YOUR_USER'@'62.214.8.8'            | def           | SELECT         | YES          |

现在您想要包含用户&#39; *****&#39; @&#39; 62.214.6 *。***&#39;这些补助金。您可以使用GRANT命令

grant all privileges on YOUR_BASE.* to '*****'@'62.214.6*.***'
  identified by password 'YOUR_PASSWORD';

如果您的IP是动态的,可能每次更改ip时都必须授予权限,或者使用通配符覆盖一系列地址&#39; 62.214。%&#39;例如

heidisql有几种连接方式,可能是使用ssh隧道,所以你没有遇到问题。

相关问题