Mysql 如何使用本地phpMyAdmin客户端访问远程服务器?
假设有一个远程服务器,并且我的计算机上本地安装了phpMyAdmin客户端。如何通过phpMyAdmin客户端访问并管理此服务器?可能吗 这是可以做到的,但您需要更改phpMyAdmin配置,请阅读以下文章: 如果由于任何原因导致链接死亡,可以使用以下步骤:Mysql 如何使用本地phpMyAdmin客户端访问远程服务器?,mysql,phpmyadmin,Mysql,Phpmyadmin,假设有一个远程服务器,并且我的计算机上本地安装了phpMyAdmin客户端。如何通过phpMyAdmin客户端访问并管理此服务器?可能吗 这是可以做到的,但您需要更改phpMyAdmin配置,请阅读以下文章: 如果由于任何原因导致链接死亡,可以使用以下步骤: 查找phpMyAdmin的配置文件,名为config.inc.php 找到$cfg['Servers'][$i]['host']变量,并将其设置为远程服务器的IP或主机名 找到$cfg['Servers'][$i]['port']变量,
- 查找phpMyAdmin的配置文件,名为
config.inc.php
- 找到
变量,并将其设置为远程服务器的IP或主机名$cfg['Servers'][$i]['host']
- 找到
变量,并将其设置为远程mysql端口。通常这是$cfg['Servers'][$i]['port']
3306
- 查找
和$cfg['Servers'][$i]['user']
变量,并将它们设置为远程服务器的用户名和密码$cfg['Servers'][$i]['password']
此外,请记住,当您这样连接时,远程数据库的用户名和密码以纯文本形式存储,因此您应该采取措施确保没有人可以访问此配置文件。或者,您可以将用户名和密码变量保留为空,以便在每次登录时提示您输入它们,这会更加安全。您可以在phpMyAdmin安装的config.inc.php文件中进行设置
$cfg['Servers'][$i]['host'] = '';
只需在底部的
/etc/phpmyadmin/config.inc.php
文件中添加以下行:
$i++;
$cfg['Servers'][$i]['host']='HostName:port'//如果不是默认值,请提供主机名和端口
$cfg['Servers'][$i]['user']='userName'//远程服务器的用户名
$cfg['Servers'][$i]['password']='password'//密码
$cfg['Servers'][$i]['auth_type']='config';//保持配置状态
您将获得当前服务器:
下拉列表,其中包含127.0.0.1
和一个您提供的$cfg['Servers'][$i]['host']
可以在服务器之间切换
更多详细信息:正如其他答案所指出的,从phpMyAdmin的本地实例访问远程MySQL服务器当然是可能的。为了实现这一点,您必须允许MySQL正在侦听的端口号的流量通过防火墙。我更喜欢稍微不同的解决方案 以下命令将设置一个SSH隧道,该隧道将从本地计算机向端口3307发出的所有请求转发到远程计算机上的端口3306:
ssh -NL 3307:localhost:3306 root@REMOTE_HOST
出现提示时,应输入远程计算机上root用户的密码。这将打开隧道。如果要在后台运行此操作,则需要添加-f
参数,并在本地计算机和远程计算机之间进行设置
SSH隧道工作后,可以通过修改
/etc/phpMyAdmin/config.inc.php
文件将远程服务器添加到本地phpMyAdmin中的服务器列表中。将以下内容添加到文件末尾:
$cfg['Servers'][$i]['verbose']='remoteserver1';//把这个换成你喜欢的。
$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++;
我写了一篇更深入的文章,以防你需要额外的帮助。关注这篇博文。你可以很容易地做到。 文件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主页将更改,并显示一个字段以选择服务器
现在,您可以通过输入数据库的用户名和密码来选择服务器并访问远程数据库。如回答中所述,如果您想要一个安全解决方案,我建议您打开一个到服务器的SSH隧道
以下是为Windows用户执行此操作的方法:
C:\Putty
)cd C:\Putty
plink-L 3307:localhost:3306username@server_ip-i路径到您的私钥。ppk
- 3307是要重定向到的本地端口
- localhost是远程服务器上MySQL数据库的地址(默认情况下为localhost)
- 3306是远程服务器上PhpMyAdmin的端口使用(默认情况下为3306)
$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';
http://127.0.0.1/phpmyadmin
sudo chmod 777 /var/lib/phpmyadmin/config.inc.php
sudo chmod 777 /etc/phpmyadmin/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;
sudo cp /etc/phpmyadmin/config.inc.php ~/
sudo cp /usr/share/doc/phpmyadmin/examples/config.manyhosts.inc.php \
/etc/phpmyadmin/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
/* 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;
}
$cfg['Servers'][$i]['host'] = '192.168.1.100';
$cfg['Servers'][$i]['port'] = '3306';
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'] = '';