php 使用 phpMyAdmin 连接到外部服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1722064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connect to external server by using phpMyAdmin
提问by Neveen
I have phpMyAdmin installed on my local machine. How can I make it connect to an external server?
我在本地机器上安装了 phpMyAdmin。如何让它连接到外部服务器?
回答by DisgruntledGoat
In the config file, change the "host" variable to point to the external server. The config file is called config.inc.phpand it will be in the main phpMyAdmin folder. There should be a line like this:
在配置文件中,将“host”变量更改为指向外部服务器。配置文件被调用config.inc.php,它将位于主 phpMyAdmin 文件夹中。应该有这样一行:
$cfg['Servers'][$i]['host'] = 'localhost';
Just change localhostto your server's IP address.
只需更改localhost为您服务器的 IP 地址即可。
Note: you may have to configure the external server to allow remote connections, but I've done this several times on shared hosting so it should be fine.
注意:您可能需要配置外部服务器以允许远程连接,但我已经在共享主机上多次这样做了,所以应该没问题。
回答by Jarrod
To set up an external DB and still use your local DB, you need to edit the config.inc.php file:
要设置外部数据库并仍然使用本地数据库,您需要编辑 config.inc.php 文件:
On Ubuntu: sudo gedit /etc/phpmyadmin/config.inc.php
The file is roughly set up like this:
该文件大致设置如下:
if (!empty($dbname)) {
//Your local db setup
$i++;
}
What you need to do is duplicate the "your local db setup" by copying and pasting it outsideof the IFstatement I've shown in the code below, and change the host to you external IP. Mine for example is:
您需要做的是通过将“您的本地数据库设置”复制并粘贴到我在下面的代码中显示的语句之外来复制它IF,并将主机更改为您的外部 IP。我的例子是:
$cfg['Servers'][$i]['host'] = '10.10.1.90:23306';
You can leave the defaults (unless you know you need to change them)
您可以保留默认值(除非您知道需要更改它们)
Save and refresh your PHPMYADMIN login page and a new dropdown should appear. You should be good to go.
保存并刷新您的 PHPMYADMIN 登录页面,应该会出现一个新的下拉列表。你应该很高兴去。
EDIT: if you want to give the server a name to select at login page, rather than having just the IP address to select, add this to the server setup:
编辑:如果您想在登录页面为服务器提供一个名称以供选择,而不是仅选择 IP 地址,请将其添加到服务器设置中:
$cfg['Servers'][$i]['verbose'] = 'Name to show when selecting your server';
It's good if you have multiple server configs.
如果您有多个服务器配置,那就太好了。
回答by Jeff Puckett
using PhpMyAdmin version 4.5.4.1deb2ubuntu2, you can set the variables in /etc/phpmyadmin/config-db.php
使用 PhpMyAdmin 版本 4.5.4.1deb2ubuntu2,您可以在 /etc/phpmyadmin/config-db.php
so set $dbserverto your server name, e.g. $dbserver='mysql.example.com';
所以设置$dbserver为您的服务器名称,例如$dbserver='mysql.example.com';
<?php
##
## database access settings in php format
## automatically generated from /etc/dbconfig-common/phpmyadmin.conf
## by /usr/sbin/dbconfig-generate-include
##
## by default this file is managed via ucf, so you shouldn't have to
## worry about manual changes being silently discarded. *however*,
## you'll probably also want to edit the configuration file mentioned
## above too.
##
$dbuser='phpmyadmin';
$dbpass='P@55w0rd';
$basepath='';
$dbname='phpmyadmin';
$dbserver='localhost';
$dbport='';
$dbtype='mysql';
回答by Samuel Diogo
at version 4.0 or above, we need to create one 'config.inc.php' or rename the 'config.sample.inc.php' to 'config.inc.php';
4.0以上版本,我们需要创建一个'config.inc.php'或将'config.sample.inc.php'重命名为'config.inc.php';
In my case, I also work with one mysql server for each environment (dev and production):
就我而言,我还为每个环境(开发和生产)使用一个 mysql 服务器:
/* others code*/
$whoIam = gethostname();
switch($whoIam) {
case 'devHost':
$cfg['Servers'][$i]['host'] = 'localhost';
break;
case 'MasterServer':
$cfg['Servers'][$i]['host'] = 'masterMysqlServer';
break;
} /* others code*/
回答by Kelno
You can use the phpmyadmin setup page (./phpmyadmin/setup) to generate a new config file (config.inc.php) for you. This file is found at the root of the phpMyAdmin directory.
您可以使用 phpmyadmin 设置页面 (./phpmyadmin/setup) 为您生成一个新的配置文件 ( config.inc.php)。该文件位于 phpMyAdmin 目录的根目录下。
Just create the config folder as prompted in setup page, add your servers, then click the 'Save' button. This will create a new config file in the config folder you just created.
只需按照设置页面中的提示创建配置文件夹,添加您的服务器,然后单击“保存”按钮。这将在您刚刚创建的 config 文件夹中创建一个新的配置文件。
You now have only to move the config.inc.phpfile to the main phpMyAdmin folder, or just copy the lines concerning the servers if you got some old configuration done already you'd like to keep.
您现在只需将config.inc.php文件移动到主 phpMyAdmin 文件夹,或者如果您已经完成了一些想要保留的旧配置,则只需复制有关服务器的行。
Don't forget to delete the config folder afterwards.
之后不要忘记删除配置文件夹。
回答by Joseph
in the config.inc.php, remove all lines with "$cfg['Servers']" , and keep ONLY the "$cfg['Servers'][$i]['host']"
在 config.inc.php 中,删除所有带有 "$cfg['Servers']" 的行,只保留 "$cfg['Servers'][$i]['host']"

