如何使用本地phpMyAdmin客户端访问远程服务器?

Mic*_*alB 121 mysql phpmyadmin

假设有一个远程服务器,我的计算机上安装了phpMyAdmin客户端.如何通过phpMyAdmin客户端访问此服务器并进行管理?那可能吗?

Sur*_*shi 157

只需将以下行添加到底部的"config.inc.php"文件中:

$i++;
$cfg['Servers'][$i]['host'] = 'HostName:port'; //provide hostname and port if other than default
$cfg['Servers'][$i]['user'] = 'userName';   //user name for your remote server
$cfg['Servers'][$i]['password'] = 'Password';  //password
$cfg['Servers'][$i]['auth_type'] = 'config';       // keep it as config
Run Code Online (Sandbox Code Playgroud)

.您将获得"当前服务器:",同时下载"127.0.0.1"和您提供的"$ cfg ['Servers'] [$ i] ['host']"服务器之间的凸轮切换.

更多详情:http://sforsuresh.in/access-remote-mysql-server-using-local-phpmyadmin/

  • `$ i +'是一个重要的观点,因为这不会让我们失去与默认`localhost`的数据库连接. (13认同)
  • /etc/phpmyadmin/config.inc.php是要更改的正确文件 (2认同)

Phi*_*oss 22

它可以完成,但你需要更改phpMyAdmin配置,请阅读这篇文章:http: //www.danielmois.com/article/Manage_remote_databases_from_localhost_with_phpMyAdmin

如果链接因任何原因而死亡,您可以使用以下步骤:

  • 找到phpMyAdmin的配置文件,名为 config.inc.php
  • 找到该$cfg['Servers'][$i]['host']变量,并将其设置为远程服务器的IP或主机名
  • 找到$cfg['Servers'][$i]['port']变量,并将其设置为远程mysql端口.通常这是3306
  • 找到$cfg['Servers'][$i]['user']$cfg['Servers'][$i]['password']变量并将其设置为远程服务器的用户名和密码

如果没有正确的服务器配置,连接可能比本地连接慢,例如,使用IP地址而不是主机名可能会稍快一些,以避免服务器必须从主机名中查找IP地址.

此外,请记住,当您像这样连接时,您的远程数据库的用户名和密码以纯文本格式存储,因此您应该采取措施确保没有人可以访问此配置文件.或者,您可以将用户名和密码变量留空,以便在每次登录时提示输入它们,这样更安全.

  • 您还需要让数据库实例上的防火墙允许流量,并且数据库服务器上的用户具有远程访问权限. (3认同)

c.h*_*ill 19

正如其他答案所指出的那样,当然可以从phpMyAdmin的本地实例访问远程MySQL服务器.为了实现这一点,您必须配置远程服务器的MySQL服务器以接受远程连接,并允许通过防火墙的流量获取MySQL正在侦听的端口号.我更喜欢涉及SSH隧道的略有不同的解决方案.

以下命令将设置SSH隧道,该隧道将从端口3307发出的所有请求从本地计算机转发到远程计算机上的端口3306:

ssh -NL 3307:localhost:3306 root@REMOTE_HOST
Run Code Online (Sandbox Code Playgroud)

出现提示时,您应该在远程计算机上输入root用户的密码.这将打开隧道.如果要在后台运行此命令,则需要添加-f参数,并在本地计算机和远程计算机之间设置无密码SSH.

在SSH隧道工作之后,您可以通过修改/etc/phpmyadmin/config.inc.php文件将远程服务器添加到本地phpMyAdmin中的服务器列表中.将以下内容添加到文件末尾:

$cfg['Servers'][$i]['verbose']       = 'Remote Server 1';// Change this to whatever you like.
$cfg['Servers'][$i]['host']          = '127.0.0.1';
$cfg['Servers'][$i]['port']          = '3307';
$cfg['Servers'][$i]['connect_type']  = 'tcp';
$cfg['Servers'][$i]['extension']     = 'mysqli';
$cfg['Servers'][$i]['compress']      = FALSE;
$cfg['Servers'][$i]['auth_type']     = 'cookie';
$i++;
Run Code Online (Sandbox Code Playgroud)

如果你需要额外的帮助,我写了一篇关于这个问题的更深入的博客文章.

  • 我认为这是安全的解决方案。如果不是绝对必要,开放 mySQL 以直接远程访问通常被认为是一种糟糕的安全做法。 (2认同)

Dul*_*ika 11

关注此博文.你可以很容易地做到这一点. https://wadsa​​shika.wordpress.com/2015/01/06/manage-remote-mysql-database-locally-using-phpmyadmin/

config.inc.php文件包含phpMyAdmin安装的配置设置.它使用一个数组来存储它可以连接的每个服务器的配置选项集,默认情况下只有一个,你自己的机器或localhost.要连接到另一台服务器,您必须向配置阵列添加另一组配置选项.您必须编辑此配置文件.

首先打开phpMyAdmin文件夹中保存的config.inc.php文件.在wamp服务器中,您可以在wamp\apps\phpmyadmin文件夹中找到它.然后将以下部分添加到该文件中.

$i++;
$cfg['Servers'][$i]['host']          = 'hostname/Ip Adress';
$cfg['Servers'][$i]['port']          = '';
$cfg['Servers'][$i]['socket']        = '';
$cfg['Servers'][$i]['connect_type']  = 'tcp';
$cfg['Servers'][$i]['extension']     = 'mysql';
$cfg['Servers'][$i]['compress']      = FALSE;
$cfg['Servers'][$i]['auth_type']     = 'config';
$cfg['Servers'][$i]['user']          = 'username';
$cfg['Servers'][$i]['password']      = 'password';
Run Code Online (Sandbox Code Playgroud)

让我们看看这个变量的含义是什么.

$i++ :- Incrementing variable for each server
$cfg[‘Servers’][$i][‘host’] :- Server host name or IP adress
$cfg[‘Servers’][$i][‘port’] :- MySQL port (Leave a blank for default port. Default MySQL port is 3306)
$cfg[‘Servers’][$i][‘socket’] :- Path to the socket (Leave a blank for default socket)
$cfg[‘Servers’][$i][‘connect_type’] :- How to connect to MySQL server (‘tcp’ or ‘socket’)
$cfg[‘Servers’][$i][‘extension’] :- php MySQL extension to use (‘mysql’ or ‘msqli’)
$cfg[‘Servers’][$i][‘compress’] :- Use compressed protocol for the MySQL connection (requires PHP >= 4.3.0)
$cfg[‘Servers’][$i][‘auth_type’] :- Method of Authentication
$cfg[‘Servers’][$i][‘username’] :- Username to the MySQL database in remote server
$cfg[‘Servers’][$i][‘password’] :- Password to the MySQL database int he remote server
Run Code Online (Sandbox Code Playgroud)

添加此配置部分后,重新启动服务器,现在您的phpMyAdmin主页将更改,它将显示一个字段以选择服务器.

现在,您可以通过输入该数据库的用户名和密码来选择服务器并访问远程数据库.


Yan*_*ckv 8

如答案c.hill回答中所述,如果您需要安全的解决方案,我建议您打开到您的服务器的SSH隧道.

以下是为Windows用户执行此操作的方法:

  1. Putty网站下载Plink和Putty ,并将文件放在您选择的文件夹中(在我的示例中C:\Putty)

  2. 打开Windows控制台并cd到Plink文件夹: cd C:\Putty

  3. 打开SSH隧道并重定向到端口3307:

    plink -L 3307:localhost:3306 username@server_ip -i path_to_your_private_key.ppk

哪里:

  • 3307是您要重定向到的本地端口
  • localhost是远程服务器上MySQL DB的地址(默认为localhost)
  • 3306是远程服务器上PhpMyAdmin的端口使用(默认为3306)

最后你可以设置PhpMyAdmin:

  1. 通过在config.inc.php末尾添加以下行,将远程服务器添加到本地PhpMyAdmin配置中

要添加的行:

$i++;   
$cfg['Servers'][$i]['verbose']          = 'Remote Dev server';
$cfg['Servers'][$i]['host']             = 'localhost';
$cfg['Servers'][$i]['port']             = '3307';
$cfg['Servers'][$i]['connect_type']     = 'tcp';
$cfg['Servers'][$i]['extension']        = 'mysqli';
$cfg['Servers'][$i]['compress']         = FALSE;
$cfg['Servers'][$i]['auth_type']        = 'cookie';
Run Code Online (Sandbox Code Playgroud)
  1. 你应该能够立即连接 http://127.0.0.1/phpmyadmin

如果您不想在每次需要连接到远程服务器时打开控制台,只需创建批处理文件(通过在.bat文件中保存2个命令行).


oo_*_*uel 6

您可以在phpMyAdmin安装的config.inc.php文件中进行设置.

$cfg['Servers'][$i]['host'] = '';
Run Code Online (Sandbox Code Playgroud)


Ken*_*Ken 5

本来可以将此添加为评论,但是我的声誉还不够高。

在版本4.5.4.1deb2ubuntu2下,我猜在其他任何版本4.5.x或更高版本中。根本不需要修改config.inc.php文件。而是在conf.d下再走一个目录。

创建一个扩展名为'.php'的新文件并添加代码行。这是一种更好的模块化方法,可以隔离每个远程数据库服务器访问信息。