当前位置:   article > 正文

phpmyadmin同时连接多个服务器的数据库_phpmyadmin 跨库关联

phpmyadmin 跨库关联

一、使用场景

从 https://blog.csdn.net/ljfphp/article/details/78717355 来的

一般来说,我们开发都会有测试环境和正式环境之分。当然,数据库也是要分开的。如果能用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'] = '';
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

我是通过在配置文件中直接写入远程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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

效果
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/428881
推荐阅读
相关标签
  

闽ICP备14008679号