配置phpMyAdmin串連多台MySQL

來源:互聯網
上載者:User

預設安裝phpMyAdmin,通常只能連一台MySql伺服器,其配置資訊是儲存在phpMyAdmin的設定檔裡的,當我們需要在多台伺服器之間進行切換登陸的時候,修改起來非常麻煩。遵照下面的配置方法,我們可以方便的使用phpMyAdmin串連多台MySQL。

方法一:登陸phpMyAdmin時輸入伺服器ip地址、使用者名稱、密碼

缺點:登陸操作比較繁瑣,而且切換伺服器時須首先退出當前所登陸的伺服器

操作步驟:修改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;

為避免修改失誤所造成的損失,強烈建議先備份 config.default.php 檔案為 config.default.php.bak

方法二:登陸phpMyAdmin時只需輸入使用者名稱、密碼,伺服器位址為下拉式清單可選,登陸後也可選擇其他伺服器快速切換。 (推薦)

優點:登陸操作簡便,登陸後切換伺服器無須退出當前串連。

操作步驟:

1. 備份phpMyAdmin根目錄下的config.sample.inc.php 檔案為 config.sample.inc.php.bak  (此操作避免修改失誤所造成的損失)

2. 備份phpMyAdmin根目錄下的config.inc.php 檔案為 config.inc.php.bak  (此操作避免修改失誤所造成的損失)

3. 將phpMyAdmin根目錄下的config.sample.inc.php 檔案重新命名為config.inc.php

4. 修改config.inc.php檔案,找到 First server 注釋部分,將其修改為以下內容

$hosts = array(
'1'=>array('host'=>'localhost','user'=>'root','password'=>'123456'),
'2'=>array('host'=>'192.168.0.1','user'=>'ciray','password'=>'123456')
);

//$hosts數組下標從1開始,host的值為伺服器ip地址,user是對應的MySql登陸使用者名稱,password的值為MySql的登陸密碼,請修改成你自己的

//$hosts數組配置了兩台伺服器,如果你有多台伺服器,請按數組下標遞增的順序添加配置資訊
/*
 * First server
 */
for($i=1;$i<=count($hosts);$i++){

/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = $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'] = $hosts[$i]['user'];  //修改使用者名稱
$cfg['Servers'][$i]['password'] = $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';


}

請注意我們使用一個for迴圈來配置所有伺服器的資訊,迴圈變數$i的初始值為1,遍曆$hosts數組中的配置資訊,迴圈體中的內容無須更改。

修改完成後儲存檔案,重新登陸,如果可以看到phpMyAdmin登陸介面中出現伺服器候選列表,說明修改正確

如果不慎修改失誤,可將操作步驟1,2中所備份的檔案進行恢複。

【特別說明】方法一、方法二不可混用,如果按照方法一進行了操作,那麼方法二將無法生效

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.