将本地phpMyAdmin与远程服务器连接 - 错误#2002

时间:2015-02-07 10:05:26

标签: php mysql phpmyadmin config remote-access

我一直在寻找一个正确的答案,并没有解决方案的运气。我的本地主机上有WampServer和phpMyAdmin。我已经在远程服务器上的phpmyadmin中创建了一个具有所有特权的用户。

  • 在文件夹wamp / apps / phpmyadmin4.1.14 /我找到了config.inc.php文件

并尝试使用以下代码将其连接到远程数据库:

<?php
$i++;
/* Authentication type */
$cfg['Servers'][$i]['verbose'] = 'mysql wampserver';
//$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysql if your server does not have mysqli */
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;

$i++;
/* Authentication type */
//$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'username';
$cfg['Servers'][$i]['password'] = 'mypass';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'example.com';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysql if your server does not have mysqli */
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
?>

结果,在phpMyAdmin中我现在有第二台服务器,但是当我选择它时 - 弹出一个错误。 MySQL错误#2002看起来像这样:

2002 - 连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接主机无法响应而建立连接失败。服务器没有响应(或未正确配置本地服务器的套接字)。

请帮助我错过了什么!

2 个答案:

答案 0 :(得分:2)

您的机器与服务器之间的通信失败。如果是权限,则不会收到死请求,您将收到权限错误。

  • 确保您的域名可用(连接到该地址并以某种方式获得答案);
  • 确保您的防火墙已打开正确的端口。这可能很棘手,因为您可以使用一个端口进入服务器,并使用不同的服务端口。确保正确编写防火墙规则,使其允许您的计算机使用外部端口查找正确的内部服务。
  • 使用INCORRECT用户名和密码。当您解决此#2002错误时,您将收到#1045访问被拒绝错误。然后你就会知道你需要担心许可并授予IP访问权。
  • 确保您的本地Wamp有可用于PhpMyAdmin的套接字以建立连接。
  • 确保您的远程MySQL允许远程连接

答案 1 :(得分:0)

您在此处列出了2个连接,因此它将显示2个连接。

因此,对于您当前的配置,列出的第二台服务器正在尝试连接到&#34; example.com &#34;服务器,如果您尝试连接到此服务器,请确保您已允许远程连接的设置,以及远程访问的帐户权限。

如果您没有尝试连接到&#34; example.com &#34;将这些行更改为您要连接的远程主机。

$cfg['Servers'][$i]['user'] = 'username';
$cfg['Servers'][$i]['password'] = 'mypass';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'example.com';

您可能还需要添加端口

$cfg['Servers'][$i]['port'] = '3307'; // MySQL port