154

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

4

13 回答 13

216

/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

您将获得 Current Server:两者的下拉菜单,127.0.0.1并且您提供的一个$cfg['Servers'][$i]['host']可以在服务器之间切换。

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

于 2014-02-28T10:31:08.263 回答
27

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

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

于 2013-05-28T21:13:38.293 回答
27

正如其他答案所指出的那样,当然可以从本地 phpMyAdmin 实例访问远程 MySQL 服务器。为此,您必须将远程服务器的 MySQL 服务器配置为接受远程连接,并允许 MySQL 正在侦听的端口号通过防火墙的流量。我更喜欢涉及SSH Tunneling的稍微不同的解决方案。

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

ssh -NL 3307:localhost:3306 root@REMOTE_HOST

出现提示时,您应该输入远程计算机上 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++;

我写了一篇更深入的博客文章,以防您需要额外的帮助。

于 2014-04-24T13:50:11.497 回答
12

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

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

首先打开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 主页将更改,它将显示一个选择服务器的字段。

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

于 2015-01-14T04:30:21.510 回答
9

As stated in answer c.hill answer, if you want a secure solution I would advise to open an SSH tunnel to your server.

Here is the way to do it for Windows users:

  1. Download Plink and Putty from the Putty website and place the files in the folder of your choice (In my example C:\Putty)

  2. Open the Windows console and cd to Plink folder: cd C:\Putty

  3. Open the SSH tunnel and redirect to the port 3307:

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

Where:

  • 3307 is the local port you want to redirect to
  • localhost is the address of the MySQL DB on the remote server (localhost by default)
  • 3306 is the port use for PhpMyAdmin on the remote server (3306 by default)

Finally you can setup PhpMyAdmin:

  1. Add the remote server to your local PhpMyAdmin configuration by adding the following line at the end of config.inc.php

Lines to add:

$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. You should be able to connect now at http://127.0.0.1/phpmyadmin

If you do not want to open the console each time you need to connect to your remote server, just create a batch file (by saving the 2 command lines in a .bat file).

于 2015-01-19T10:41:35.737 回答
7

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

$cfg['Servers'][$i]['host'] = '';
于 2013-05-28T21:15:45.563 回答
5

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

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

创建一个带有“.php”扩展名的新文件并添加行。这是一种更好的模块化方法,并且隔离了每个远程数据库服务器的访问信息。

于 2017-03-14T19:16:02.927 回答
3

找到文件库/config.default.php

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

然后将其设置为true

笔记:

在 ubuntu 上的路径/usr/share/phpmyadmin/libraries/config.default.php中的文件

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

于 2020-05-04T04:16:31.580 回答
2

Method 1 ( for multiserver )

First , lets make a backup of original config.

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

Now in /usr/share/doc/phpmyadmin/examples/ you will see a file config.manyhosts.inc.php. Just copy in to /etc/phpmyadmin/ using command bellow:

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

Edit the config.inc.php

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

Search for :

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

And add your ip or hostname array save ( in nano CTRL+X press Y ) and exit . Done

Method 2 ( single server ) Edit the config.inc.php

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

Search for :

/* Server parameters */
if (empty($dbserver)) $dbserver = 'localhost';
$cfg['Servers'][$i]['host'] = $dbserver;

if (!empty($dbport) || $dbserver != 'localhost') {
    $cfg['Servers'][$i]['connect_type'] = 'tcp';
    $cfg['Servers'][$i]['port'] = $dbport;
}

And replace with:

$cfg['Servers'][$i]['host'] = '192.168.1.100';
$cfg['Servers'][$i]['port'] = '3306';

Remeber to replace 192.168.1.100 with your own mysql ip server.

Sorry for my bad English ( google translate have the blame :D )

于 2018-05-18T06:22:44.003 回答
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

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

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;

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

于 2016-09-26T07:08:12.180 回答
2

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

于 2017-01-18T05:29:36.747 回答
0

在安装了 Wamp 服务器的 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'] = '';
于 2019-12-09T06:22:39.137 回答
-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>'

供参考:允许 IP 访问受保护的 PhpMyAdmin

于 2018-02-12T11:22:58.517 回答