phpmyadmin 同时连接多个服务器的数据库
一、使用场景
一般来说,我们开发都会有测试环境和正式环境之分。当然,数据库也是要分开的。如果能用phpmyadmin直接访问两台服务器上的mysql就好了。这就是需求。
二、解决方案
1、找到phpmyadmin文件夹下面的config.sample.inc.php,重命名为config.inc.php。
2、打开config.inc.php,我们会发现里面有一些基本配置,是连接到localhost的。
3、如何连接单个远程服务器
//测试服务器数据库配置文件 $cfg['Servers'][$i]['auth_type'] = 'config'; $cfg['Servers'][$i]['host'] = '远程ip'; $cfg['Servers'][$i]['user'] = 'username'; $cfg['Servers'][$i]['password'] = 'pwd'; $cfg['Servers'][$i]['extension'] = 'mysqli'; $cfg['Servers'][$i]['AllowNoPassword'] = true; $cfg['Lang'] = '';
我是通过在配置文件中直接写入远程ip等,实现了本地连接远程的目的。
4、如何连接多个远程服务器
//这里把远程服务器的用户名,密码等,拼接为一个多维数组 $connect_hosts = array( '1'=>array( "host" => "localhost", //本地服务器 "user" => "root", "password" => "" ), '2' => array( "host" => "服务器IP", //服务器1 "user" => "username", "password" => "pwd" ), '3' => array( "host" => "服务器ip", //服务器2 "user" => "username", "password" => "pwd" ) ); for ($i=1;$i<=count($connect_hosts);$i++) { /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ $cfg['Servers'][$i]['host'] = $connect_hosts[$i]['host']; //修改host $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; /* Select mysqli if your server has it */ $cfg['Servers'][$i]['extension'] = 'mysql'; $cfg['Servers'][$i]['AllowNoPassword'] = true; $cfg['Servers'][$i]['user'] = $connect_hosts[$i]['user']; //修改用户名 $cfg['Servers'][$i]['password'] = $connect_hosts[$i]['password']; //密码 /* rajk - for blobstreaming */ $cfg['Servers'][$i]['bs_garbage_threshold'] = 50; $cfg['Servers'][$i]['bs_repository_threshold'] = '32M'; $cfg['Servers'][$i]['bs_temp_blob_timeout'] = 600; $cfg['Servers'][$i]['bs_temp_log_threshold'] = '32M'; }
这里需要注意:
(1)for循环的时候,i要从1开始,不要从0开始(2)配置文件中有个′i要从1开始,不要从0开始(2)配置文件中有个′i = 0’,记得注释掉。也就是注释掉无关的代码
三、结果展示
1、本地输入:localhost/phpmyadmin
这里我们选择自己要连接的服务器即可。
分类:
PHP&mysql
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2016-11-02 MySQL的保留关键字,使用时尽量避免