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

时间:2013-05-28 21:11:39

标签: mysql phpmyadmin

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

13 个答案:

答案 0 :(得分:144)

只需将以下行添加到底部的/etc/phpmyadmin/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

。您将获得“当前服务器:”下拉同时使用“127.0.0.1”以及您提供的“$ cfg ['Servers'] [$ i] ['host']”服务器之间的凸轮切换。“ p>

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

答案 1 :(得分:21)

可以这样做,但是你需要更改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地址。

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

答案 2 :(得分:17)

正如其他答案所指出的那样,当然可以从phpMyAdmin的本地实例访问远程MySQL服务器。要实现这一点,您必须configure the remote server's MySQL server to accept remote connections,并允许通过防火墙的流量获取MySQL正在侦听的端口号。我更喜欢涉及SSH Tunnelling的稍微不同的解决方案。

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

ssh -NL 3307:localhost:3306 root@REMOTE_HOST

出现提示时,您应该在远程计算机上输入root用户的密码。这将打开隧道。如果要在后台运行此操作,则需要添加-f参数,并在本地计算机和远程计算机之间设置Passwordless 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++;

如果您需要其他帮助,我会更深入地了解blog post这个问题。

答案 3 :(得分:11)

关注此博文。你可以很容易地做到这一点。 https://wadsashika.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';

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

$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

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

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

答案 4 :(得分:8)

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

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

  1. Putty website下载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

  4. 其中:

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

    最后你可以设置PhpMyAdmin:

    1. 通过在 config.inc.php
    2. 末尾添加以下行,将远程服务器添加到本地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';
      
      1. 您应该可以立即通过http://127.0.0.1/phpmyadmin
      2. 进行连接

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

答案 5 :(得分:6)

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

$cfg['Servers'][$i]['host'] = '';

答案 6 :(得分:4)

我会将此作为评论添加,但我的声誉还不够高。

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

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

答案 7 :(得分:3)

找到文件 libraries / config.default.php

然后找到 $ cfg ['AllowArbitraryServer'] = false;

然后将其设置为 true

注意:

在ubuntu上路径 /usr/share/phpmyadmin/libraries/config.default.php

中的文件

然后,您将在PHPMyAdmin主页上找到一个新的文件名SERVER,您可以为本地数据库添加任何IP或本地主机。

答案 8 :(得分:2)

在Ubuntu

您需要修改PHPMyAdmin文件夹中的单个文件,即“config.inc.php”。只需将以下行添加到“config.inc.php”。

文件位置:/var/lib/phpmyadmin/config.inc.php或                 /etc/phpmyadmin/config.inc.php

也许您没有编辑该文件的权限,只需使用此命令授予权限

sudo chmod 777 /var/lib/phpmyadmin/config.inc.php

OR(在不同的系统中,您可能需要检查这两个位置)

sudo chmod 777 /etc/phpmyadmin/config.inc.php

然后将代码复制并粘贴到config.inc.php文件

    $i++;
    $cfg['Servers'][$i]['auth_type']     = 'cookie';
    $cfg['Servers'][$i]['verbose'] = 'Database Server 2';
    $cfg['Servers'][$i]['host'] = '34.12.123.31';
    $cfg['Servers'][$i]['connect_type']  = 'tcp';
    $cfg['Servers'][$i]['compress']      = false;
    $cfg['Servers'][$i]['AllowNoPassword'] = false;

使用您的服务器详细信息进行适当的更改

答案 9 :(得分:1)

转到最底部的文件\ phpMyAdmin \ config.inc.php,更改主机,用户名,密码等主机详细信息。

答案 10 :(得分:0)

方法1 (对于多服务器)

首先,让我们备份原始配置。

AutoFilter()

现在在 / usr / share / doc / phpmyadmin / examples / 中,您将看到一个文件 config.manyhosts.inc.php 。只需复制到 / etc / phpmyadmin / 即可 使用命令bellow:

Sub nn()
    Dim sortRng As Range

    With ActiveSheet.UsedRange ' reference all data in active sheet
        With .Offset(, .Columns.Count).Resize(, 1) ' get a helper column right outside data
            .Formula = "=ROW()" ' fill it with sequential numbers from top to down
            .Value = .Value ' get rid of formulas
            Set sortRng = .Cells ' store the helper range
        End With

        With .Resize(, .Columns.Count + 1) ' consider data and the helper range
            .Sort key1:=.Cells(1, 20), order1:=xlAscending, Header:=xlNo ' sort it by data in column 20 
            .AutoFilter Field:=20, Criteria1:=">=01/01/2018" ' filter it for data greater than 2017
            .Resize(.Rows.Count - 1).Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete ' delete filtered data
            .Parent.AutoFilterMode = False ' remove filter
            .Sort key1:=sortRng(1, 1), order1:=xlAscending, Header:=xlNo ' sort things back by means of helper column
            .Columns(.Columns.Count).ClearContents ' clear helper column
        End With
    End With
End Sub

修改 config.inc.php

sudo cp /etc/phpmyadmin/config.inc.php      ~/ 

搜索:

sudo cp /usr/share/doc/phpmyadmin/examples/config.manyhosts.inc.php \
        /etc/phpmyadmin/config.inc.php

添加你的ip或主机名数组保存(在nano CTRL + X按Y)并退出。完成

方法2 (单台服务器) 修改 config.inc.php

sudo nano /etc/phpmyadmin/config.inc.php 

搜索:

$hosts = array (
    "foo.example.com",
    "bar.example.com",
    "baz.example.com",
    "quux.example.com",
);

并替换为:

sudo nano /etc/phpmyadmin/config.inc.php 

记得将 192.168.1.100 替换为您自己的mysql ip服务器。

抱歉我的英语不好(google翻译有责任:D)

答案 11 :(得分:0)

在安装了Wamp Server的Windows中,您可能会找到配置文件

C:\wamp64\apps\phpmyadmin4.8.4\config.inc.php

适当更改空心线

$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['port'] = 3306;//$wampConf['mysqlPortUsed'];
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';

答案 12 :(得分:-1)

删除/etc/http/conf.d/phpMyAdmin.conf

的完整条目

以下文件中的

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       #ADD following line:
       Require all granted
       Require ip 127.0.0.1
       Require ip ::1
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     #CHANGE following 2 lines:
     Order Allow,Deny
     Allow from All
     Allow from 127.0.0.1
     Allow from ::1
   </IfModule>
</Directory>

然后,

在MySQL提示符下运行以下命令,

GRANT ALL ON *.* to root@localhost IDENTIFIED BY 'root@<password>'

GRANT ALL ON *.* to root@'%' IDENTIFIED BY 'root@<password>'

供参考:Allow IP to Access Secured PhpMyAdmin