目录
✅ 1. Ensure Remote MySQL Access is Enabled
Steps on the remote MySQL server:
✅ 2. Configure phpMyAdmin to Connect to Remote Server
Edit phpMyAdmin’s configuration file:
✅ 3. Secure the Connection (Highly Recommended)
Best practices:
✅ 4. Test the Connection
Summary
首页 数据库 php我的管理员 如何将phpmyadmin连接到远程数据库

如何将phpmyadmin连接到远程数据库

Aug 02, 2025 am 11:01 AM
远程数据库

确保远程MySQL服务器启用远程访问,修改bind-address为0.0.0.0,创建允许从phpMyAdmin服务器IP登录的用户并授权,防火墙开放3306端口;2. 在phpMyAdmin服务器编辑config.inc.php文件,添加远程数据库IP和端口配置;3. 推荐通过SSH隧道或SSL/TLS加密连接以保障安全;4. 重启Web服务器并访问phpMyAdmin页面,使用远程MySQL账户登录测试连接,若失败则检查日志、网络连通性和权限设置。完成以上步骤即可安全实现phpMyAdmin连接远程数据库。

How to connect phpMyAdmin to a remote database

Connecting phpMyAdmin to a remote database is a common need when managing MySQL/MariaDB servers hosted on a different machine (like a VPS, cloud server, or another networked device). By default, phpMyAdmin runs locally and connects to a local database, but it can be configured to access a remote MySQL server. Here’s how to do it properly and securely.

How to connect phpMyAdmin to a remote database

✅ 1. Ensure Remote MySQL Access is Enabled

Before phpMyAdmin can connect, the remote MySQL server must allow external connections.

Steps on the remote MySQL server:

  • Edit MySQL config file (usually /etc/mysql/mysql.conf.d/mysqld.cnf or /etc/my.cnf):

    How to connect phpMyAdmin to a remote database
    # Change this line:
    bind-address = 127.0.0.1
    # To:
    bind-address = 0.0.0.0

    ⚠️ This allows MySQL to accept connections from any IP. Use with caution and secure via firewall.

  • Restart MySQL:

    How to connect phpMyAdmin to a remote database
    sudo systemctl restart mysql
  • Create a user with remote access:

    CREATE USER 'pma_user'@'your_phpmyadmin_server_ip' IDENTIFIED BY 'strong_password';
    GRANT ALL PRIVILEGES ON *.* TO 'pma_user'@'your_phpmyadmin_server_ip';
    FLUSH PRIVILEGES;

    Replace your_phpmyadmin_server_ip with the actual IP of the server where phpMyAdmin is running. Use % for any host (less secure).

  • Open port 3306 in the firewall (if applicable):

    sudo ufw allow from your_phpmyadmin_ip to any port 3306

✅ 2. Configure phpMyAdmin to Connect to Remote Server

Now, tell phpMyAdmin to connect to the remote MySQL host instead of localhost.

Edit phpMyAdmin’s configuration file:

On your phpMyAdmin server, open the config file:

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

Add the following block before any existing server blocks:

$i = 1;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = 'remote_mysql_server_ip';
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;

Replace remote_mysql_server_ip with the actual IP or domain of your remote MySQL server.

  • auth_type = 'cookie' lets you log in with MySQL credentials.
  • You can have multiple server entries if needed.

? If you're using a custom setup (e.g., manual phpMyAdmin install), edit config.inc.php in the phpMyAdmin directory.


Connecting over the internet without encryption exposes credentials and data.

Best practices:

  • Use SSH tunneling (most secure):

    ssh -L 3307:localhost:3306 user@remote_mysql_server

    Then in phpMyAdmin config:

    $cfg['Servers'][$i]['host'] = '127.0.0.1';
    $cfg['Servers'][$i]['port'] = '3307';

    This routes MySQL traffic through an encrypted SSH tunnel.

  • Use SSL/TLS: Configure MySQL to require SSL and set in phpMyAdmin:

    $cfg['Servers'][$i]['ssl'] = true;
    $cfg['Servers'][$i]['ssl_ca'] = '/path/to/ca-cert.pem';
  • Avoid exposing port 3306 publicly. Use a firewall or VPN.


✅ 4. Test the Connection

  • Restart your web server:

    sudo systemctl restart apache2
    # or
    sudo systemctl restart nginx
  • Visit your phpMyAdmin URL (e.g., http://your-server/phpmyadmin)

  • Log in with the remote MySQL user credentials you created.

  • If login fails, check:

    • MySQL error log: /var/log/mysql/error.log
    • Network connectivity: telnet remote_ip 3306
    • User privileges and host permissions in MySQL

Summary

To connect phpMyAdmin to a remote database:

  • ✅ Enable remote access on MySQL (bind-address, user privileges, firewall)
  • ✅ Configure config.inc.php with remote host details
  • ✅ Secure the connection (SSH tunnel or SSL)
  • ✅ Test and troubleshoot as needed

It’s not hard, but security is critical — never leave MySQL open to the public internet without safeguards.

Basically, it’s about telling phpMyAdmin where to connect and making sure the remote database says “yes” to that connection — safely.

以上是如何将phpmyadmin连接到远程数据库的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

Laravel 教程
1602
29
PHP教程
1505
276
如何使用phpmyadmin优化数据库表(例如,优化表)? 如何使用phpmyadmin优化数据库表(例如,优化表)? Jul 11, 2025 am 12:47 AM

优化数据库表可提升性能,具体步骤如下:1.登录phpMyAdmin并选择对应数据库;2.从表列表中选中需优化的表,通常是有高频插入、更新或删除操作的表;3.在“Withselected:”菜单中选择“Optimizetable”并确认执行。优化时MySQL会重建表以减少磁盘I/O、更新索引统计信息并释放已删除或修改数据所占空间,但该操作会短暂锁表,建议在低峰期进行。并非所有表都需要定期优化,频繁变更的表每月优化一次较合适,其他表可视情况而定。

PhpMyAdmin如何显示并允许编辑列的默认值和auto_increment属性? PhpMyAdmin如何显示并允许编辑列的默认值和auto_increment属性? Jul 23, 2025 am 04:19 AM

phpMyAdMindisPlaysAndAllowSitingofColumnDefaultSandaUto-IncrementSettingSetthetBableStructureView.1.defaultValuesAreshownInthownintheNthowninthe“默认”列,youcaneditthiTtheDittheTtheTtheTtheMviaDlopDownorInpodfield,supportingNull,current_timestamp,current_timestamp,under_timestamp,user(usercustomv),orcustomv

是否建议在生产服务器上使用PhpMyAdmin,应采取哪些预防措施? 是否建议在生产服务器上使用PhpMyAdmin,应采取哪些预防措施? Jul 16, 2025 am 12:03 AM

使用phpMyAdminonAproductionserVerisposibleButrequirestrictSecurityMeasures.1.SecureAccessByusingStrongaUthentication,LimitingIpAccess,Enabling2fa,andchangingthedefthedefthedefthedefthedthedthedthedthedthedthedthedefaulturl.2.

数据库或表phpmyadmin的数量有效地显示和管理的局限性是什么? 数据库或表phpmyadmin的数量有效地显示和管理的局限性是什么? Jul 12, 2025 am 12:57 AM

phpMyAdmindoesnotimposeahardlimitondatabasesortables,butperformancedegradesbasedonserverresources.1.AvailableRAM,CPUpower,anddiskI/Ospeedsignificantlyimpactusability.2.Modestserverstypicallyhandle50–100databases,whilehigh-performancesetupscanmanagehu

显示或编辑表内容时,PhpMyAdmin如何处理二进制数据(BLOB)? 显示或编辑表内容时,PhpMyAdmin如何处理二进制数据(BLOB)? Jul 20, 2025 am 04:12 AM

phpMyAdmin处理BLOB数据的方式实用但有限。1.查看BLOB列时,通常显示占位符如[BLOB-25B],以避免直接渲染大量或不可读内容;对于文本型BLOB(如JSON),可点击查看具体内容。2.编辑BLOB字段时,小的文本型BLOB可通过文本框编辑,而大型或二进制BLOB(如图片)则无法内联编辑,需通过下载或上传文件进行替换。3.配置选项$cfg['DisplayBinaryAsHex']、$cfg['DisplayBlob']和$cfg['SaveCellsAtOnce']可控制BL

如何在phpmyadmin中禁用特定功能或选项卡以进行安全性或简单性? 如何在phpmyadmin中禁用特定功能或选项卡以进行安全性或简单性? Jul 14, 2025 am 12:21 AM

要禁用phpMyAdmin中的特定功能或标签页,可通过修改配置文件实现。1.编辑config.inc.php文件,使用如$cfg['ShowPhpInfo']=false;等设置隐藏指定标签;2.基于用户角色限制访问,通过创建权限受限的MySQL用户并配置$cfg['AllowUserDropDatabase']=false;等参数控制功能可见性;3.关闭不需要的功能,如设置$cfg['AllowArbitraryServer']=false;以禁用任意服务器输入;4.可选地,使用自定义主题隐藏

如何更新phpmyadmin 如何更新phpmyadmin Aug 02, 2025 am 06:57 AM

Checkyourinstallationmethodtodeterminethecorrectupdateapproach.2.Forpackagemanagerinstallations,usesudoaptupdateandsudoaptupgradephpmyadminorreinstall.3.Formanualupdates,downloadthelatestversionfromphpmyadmin.net,backupyourcurrentinstallationandconfi

phpmyadmin的表概述中的'开销”列表示什么? phpmyadmin的表概述中的'开销”列表示什么? Jul 14, 2025 am 12:33 AM

表的开销由MySQL内部数据管理产生,常见原因:1.删除大量行;2.更新变长字段导致空间减少;3.频繁增删操作。phpMyAdmin显示此信息用于提示可优化的表。修复方法为使用“Optimizetable”功能,该操作重建表并回收空间,适用于MyISAM和InnoDB引擎,建议定期执行以保持数据库效率。

See all articles