MySQL 如何使用本地 phpMyAdmin 客户端访问远程服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16801573/
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
How to access remote server with local phpMyAdmin client?
提问by MichalB
Assuming there is a remote server and I have phpMyAdmin client installed localy on my computer. How can I access this server and manage it via phpMyAdmin client? Is that possible?
假设有一个远程服务器并且我在我的计算机上本地安装了 phpMyAdmin 客户端。如何通过 phpMyAdmin 客户端访问此服务器并对其进行管理?那可能吗?
回答by Suresh Kamrushi
Just add below lines to your /etc/phpmyadmin/config.inc.php
file in the bottom:
只需将以下几行添加/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
. You will get “Current Server:” drop down with both “127.0.0.1” and one what you have provided with “$cfg['Servers'][$i]['host']” cam switch between the servers.
. 您将获得“当前服务器:”下拉菜单,其中包含“127.0.0.1”和您提供的“$cfg['Servers'][$i]['host']”凸轮在服务器之间切换。
more Details: http://sforsuresh.in/access-remote-mysql-server-using-local-phpmyadmin/
更多详情:http: //sforsuresh.in/access-remote-mysql-server-using-local-phpmyadmin/
回答by Phil Cross
It can be done, but you need to change the phpMyAdmin configuration, read this post: http://www.danielmois.com/article/Manage_remote_databases_from_localhost_with_phpMyAdmin
可以做到,但是需要更改phpMyAdmin的配置,阅读这篇文章:http: //www.danielmois.com/article/Manage_remote_databases_from_localhost_with_phpMyAdmin
If for any reason the link dies, you can use the following steps:
如果由于任何原因链接失效,您可以使用以下步骤:
- Find phpMyAdmin's configuration file, called
config.inc.php
- Find the
$cfg['Servers'][$i]['host']
variable, and set it to the IP or hostname of your remote server - Find the
$cfg['Servers'][$i]['port']
variable, and set it to the remote mysql port. Usually this is3306
- Find the
$cfg['Servers'][$i]['user']
and$cfg['Servers'][$i]['password']
variables and set these to your username and password for the remote server
- 找到phpMyAdmin的配置文件,名为
config.inc.php
- 找到
$cfg['Servers'][$i]['host']
变量,并将其设置为远程服务器的 IP 或主机名 - 找到该
$cfg['Servers'][$i]['port']
变量,并将其设置为远程 mysql 端口。通常这是3306
- 找到
$cfg['Servers'][$i]['user']
和$cfg['Servers'][$i]['password']
变量并将它们设置为远程服务器的用户名和密码
Without proper server configuration, the connection may be slower than a local connection for example, it's would probably be slightly faster to use IP addresses instead of host names to avoid the server having to look up the IP address from the hostname.
如果没有正确的服务器配置,连接可能比本地连接慢,例如,使用 IP 地址而不是主机名可能会稍微快一点,以避免服务器必须从主机名中查找 IP 地址。
In addition, remember that your remote database's username and password is stored in plain text when you connect like this, so you should take steps to ensure that no one can access this config file. Alternatively, you can leave the username and password variables empty to be prompted to enter them each time you log in, which is a lot more secure.
此外,请记住,当您像这样连接时,远程数据库的用户名和密码以纯文本形式存储,因此您应该采取措施确保没有人可以访问此配置文件。或者,您可以将用户名和密码变量留空,以便在每次登录时提示输入它们,这样更安全。
回答by c.hill
It is certainly possible to access a remote MySQL server from a local instance of phpMyAdmin, as the other answers have pointed out. And for that to work, you have to configure the remote server's MySQL server to accept remote connections, and allow traffic through the firewall for the port number that MySQL is listening to. I prefer a slightly different solution involving SSH Tunnelling.
正如其他答案所指出的那样,当然可以从 phpMyAdmin 的本地实例访问远程 MySQL 服务器。为此,您必须将远程服务器的 MySQL 服务器配置为接受远程连接,并允许 MySQL 正在侦听的端口号的流量通过防火墙。我更喜欢涉及SSH Tunneling的略有不同的解决方案。
The following command will set up an SSH tunnel which will forward all requests made to port 3307 from your local machine to port 3306 on the remote machine:
以下命令将设置一个 SSH 隧道,它将所有从本地机器对端口 3307 发出的请求转发到远程机器上的端口 3306:
ssh -NL 3307:localhost:3306 root@REMOTE_HOST
When prompted, you should enter the password for the root user on the remote machine. This will open the tunnel. If you want to run this in the background, you'll need to add the -f
argument, and set up Passwordless SSHbetween your local machine and the remote machine.
出现提示时,您应该输入远程计算机上 root 用户的密码。这将打开隧道。如果你想在后台运行它,你需要添加-f
参数,并在本地机器和远程机器之间设置无密码 SSH。
After you've got the SSH tunnel working, you can add the remote server to the servers list in your local phpMyAdmin by modifying the /etc/phpmyadmin/config.inc.php
file. Add the following to the end of the file:
使 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++;
I wrote a more in-depth blog postabout exactly this, in case you need additional help.
回答by Dulanga Sashika
Follow this blog post. You can do it very easily. https://wadsashika.wordpress.com/2015/01/06/manage-remote-mysql-database-locally-using-phpmyadmin/
关注这篇博文。你可以很容易地做到这一点。 https://wadsashika.wordpress.com/2015/01/06/manage-remote-mysql-database-locally-using-phpmyadmin/
The file config.inc.phpcontains the configuration settings for your phpMyAdmin installation. It uses an array to store sets of config options for every server it can connect to and by default there is only one, your own machine, or localhost. In order to connect to another server, you would have to add another set of config options to the config array. You have to edit this configuration file.
文件config.inc.php包含 phpMyAdmin 安装的配置设置。它使用一个数组来存储它可以连接的每台服务器的配置选项集,默认情况下只有一个,您自己的机器或本地主机。为了连接到另一台服务器,您必须向配置数组添加另一组配置选项。您必须编辑此配置文件。
First open config.inc.phpfile held in phpMyAdminfolder. In wampserver, you can find it in wamp\apps\phpmyadminfolder. Then add following part to that file.
首先打开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';
Let's see what is the meaning of this variables.
让我们看看这个变量的含义是什么。
$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
After adding this configuration part, restart you server and now your phpMyAdmin home page will change and it will show a field to select the server.
添加此配置部分后,重新启动您的服务器,现在您的 phpMyAdmin 主页将发生变化,它将显示一个用于选择服务器的字段。
Now you can select you server and access your remote database by entering username and password for that database.
现在您可以选择您的服务器并通过输入该数据库的用户名和密码来访问您的远程数据库。
回答by Yannickv
As stated in answer c.hillanswer, if you want a secure solutionI would advise to open an SSH tunnel to your server.
正如回答c.hill 的回答中所述,如果您想要一个安全的解决方案,我建议您打开一个到您的服务器的 SSH 隧道。
Here is the way to do it for Windowsusers:
以下是为Windows用户执行此操作的方法:
Download Plink and Putty from the Putty websiteand place the files in the folder of your choice (In my example
C:\Putty
)Open the Windows console and cd to Plink folder:
cd C:\Putty
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
从Putty 网站下载 Plink 和 Putty并将文件放在您选择的文件夹中(在我的示例中
C:\Putty
)打开 Windows 控制台并 cd 到 Plink 文件夹:
cd C:\Putty
打开 SSH 隧道并重定向到端口 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)
- 3307 是您要重定向到的本地端口
- localhost 是远程服务器上 MySQL DB 的地址(默认为 localhost)
- 3306 是远程服务器上 PhpMyAdmin 使用的端口(默认为 3306)
Finally you can setup PhpMyAdmin:
最后你可以设置 PhpMyAdmin:
- Add the remote server to your local PhpMyAdmin configuration by adding the following line at the end of config.inc.php
- 通过在config.inc.php末尾添加以下行,将远程服务器添加到本地 PhpMyAdmin 配置
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';
- You should be able to connect now at
http://127.0.0.1/phpmyadmin
- 您现在应该可以连接
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).
如果您不想在每次需要连接到远程服务器时都打开控制台,只需创建一个批处理文件(通过将 2 个命令行保存在 .bat 文件中)。
回答by oo_miguel
You can set in the config.inc.php file of your phpMyAdmin installation.
您可以在 phpMyAdmin 安装的 config.inc.php 文件中进行设置。
$cfg['Servers'][$i]['host'] = '';
回答by Ken
I would have added this as a comment, but my reputation is not yet high enough.
我会添加这个作为评论,但我的声誉还不够高。
Under version 4.5.4.1deb2ubuntu2, and I am guessing any other versions 4.5.x or newer. There is no need to modify the config.inc.php file at all. Instead go one more directory down conf.d.
在 4.5.4.1deb2ubuntu2 版本下,我猜测任何其他版本 4.5.x 或更新版本。根本不需要修改 config.inc.php 文件。而是转到 conf.d 下的另一个目录。
Create a new file with the '.php' extension and add the lines. This is a better modularized approach and isolates each remote database server access information.
创建一个扩展名为“.php”的新文件并添加行。这是一种更好的模块化方法,可以隔离每个远程数据库服务器访问信息。
回答by byteC0de
In Ubuntu
在 Ubuntu 中
Just you need to modify a single file in PHPMyAdmin folder i.e. “config.inc.php”.Just add below lines to your “config.inc.php”.
只需要修改 PHPMyAdmin 文件夹中的一个文件,即“config.inc.php”。只需将以下几行添加到“config.inc.php”中。
File location : /var/lib/phpmyadmin/config.inc.php
OR
/etc/phpmyadmin/config.inc.php
文件位置:/var/lib/phpmyadmin/config.inc.php
或
/etc/phpmyadmin/config.inc.php
Maybe you don't have the permission for editing that file, just give the permission using this command
也许您没有编辑该文件的权限,只需使用此命令授予权限
sudo chmod 777 /var/lib/phpmyadmin/config.inc.php
OR (in different systems you may have to check with these two locations)
或(在不同的系统中,您可能需要检查这两个位置)
sudo chmod 777 /etc/phpmyadmin/config.inc.php
Then copy and paste the code in your config.inc.php
file
然后将代码复制并粘贴到您的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;
And make the appropriate changes with your server details
并使用您的服务器详细信息进行适当的更改
回答by Patrick R
Go to file \phpMyAdmin\config.inc.php at the very bottom, change the hosting details such as host, username, password etc.
转到最底部的文件\phpMyAdmin\config.inc.php,更改主机详细信息,例如主机、用户名、密码等。
回答by Mohannd
As I test It find the file config.default.php
当我测试它找到文件config.default.php
then find $cfg['AllowArbitraryServer'] = false;
然后找到 $cfg['AllowArbitraryServer'] = false;
then set It to true
然后将其设置为true
note: on ubuntu the file in the path /usr/share/phpmyadmin/libraries/config.default.php
注意:在 ubuntu 上,路径/usr/share/phpmyadmin/libraries/config.default.php 中的文件
then you will find a new filed name SERVER in the main PHPMyAdmin page, you can add to it any IP or localhost for the local database.
然后您将在主 PHPMyAdmin 页面中找到一个新的文件名 SERVER,您可以向其中添加本地数据库的任何 IP 或 localhost。