天天看點

phpmyadmin 顯式ip

預設安裝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登陸界面中出現伺服器候選清單,說明修改正确