phpMyadmin-连接多个mysql

phpMyAdmin说明文档:https://docs.phpmyadmin.net/zh_CN/latest/config.html 

1.首先修改,phpMyAdmin/libraries/config.default.php 


/** 
 * allow login to any user entered server in cookie based authentication 
 * 
 * @global boolean $cfg['AllowArbitraryServer'] 
 */  
$cfg['AllowArbitraryServer'] = true; //默认是false,改成true

 

2.phpMyAdmin根目录下新建文件 config.inc.php ,复制以下内容

<?php

/*把远程服务器的用户名,密码等,拼接为一个多维数组
    数组下标要从1开始,从0开始会报错
*/
$connect_hosts = array(
  '1'=>array(
    "host"   => "127.0.0.1",  //mysql1
    "user"   => "root",
    "password" => "root"
  ),
  '2' => array(
    "host"   => "", //mysql2
    "user"   => "root",
    "password" => ""
  ),
  '3' => array(
    "host"   => "", //mysql2
    "user"   => "root",
    "password" => ""
  )
);

for ($i=1;$i<=count($connect_hosts);$i++) {

  /* Authentication type */
  $cfg['Servers'][$i]['auth_type'] = 'cookie';//cookie改成config会直接登录,
  /* 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'] = 'mysqli';//mysqli | 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';

}

 如下图,点击就可以切换链接了

 

 

3. 在 phpMyAdmin\libraries\auth\cookie.auth.lib.php 最下面插入下面代码

 <script type="text/javascript">
        window.onload = function() {
            let h=document.createElement("option")
            let t=document.createTextNode("请选择");
                h.appendChild(t);
            let att=document.createAttribute("value");
                att.value="0";
                h.setAttributeNode(att);
            let att1=document.createAttribute("selected");
                att1.value="selected";
                h.setAttributeNode(att1);
            let list=document.getElementById("select_server");
            list.insertBefore(h,list.childNodes[0]);
        }
        document.getElementById("select_server").onchange = function(e){
            e = e || window.event;

            let str='<?php echo json_encode($GLOBALS['cfg']['Servers']);?>';
            console.log('-----------');
            // console.log(e.target.options[e.target.selectedIndex]);
            console.log(e.target.value);
            let i=e.target.value;
            let arr=JSON.parse(str)
            if(i==0){
                document.forms['login_form'].elements['pma_servername'].value = '';
                document.forms['login_form'].elements['pma_username'].value = '';
                document.forms['login_form'].elements['pma_password'].value = '';
                return false;
            }
            document.forms['login_form'].elements['pma_servername'].value = arr[i].host;
            document.forms['login_form'].elements['pma_username'].value = arr[i].user;
            document.forms['login_form'].elements['pma_password'].value = arr[i].password;
        }
    </script>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值