配置phpmyadmin使登錄時可填寫IP管理多台MySQL 連接多個數據庫 自動登錄


一、如何設置phpMyAdmin自動登錄?

首先在根目錄找到config.sample.inc.php復制一份文件名改為config.inc.php(如果已經存在 config.inc.php 文件,則直接修改該文件即可)。
打開config.inc.php 找到 $cfg['Servers'][$i]['auth_type'],將

復制代碼 代碼如下:
$cfg['Servers'][$i]['auth_type'] = 'cookie';

改成

復制代碼 代碼如下:
$cfg['Servers'][$i]['auth_type'] = 'config';

然后在下面追加如下代碼:

復制代碼 代碼如下:
$cfg['Servers'][$i]['user']          = 'root';      // 設置的mysql用戶名
$cfg['Servers'][$i]['password']      = '123456';    // 設置的mysql密碼

 

二、如何取消phpMyAdmin自動登錄?

只需把

復制代碼 代碼如下:
$cfg['Servers'][$i]['auth_type'] = 'config';


改成

復制代碼 代碼如下:
$cfg['Servers'][$i]['auth_type'] = 'cookie';

保存即可。 

溫馨提示:
$cfg['Servers'][$i]['auth_type'] 有三個待選項值,即 cookie、http、config。用的比較多的是 cookie與config。當在正式環境時,用 cookie,要求用戶必須輸入正確的用戶名與密碼,而在本地測試服務器時,一般用 config,省得session失效后又得輸入用戶名與密碼,以節省開發時間

 

#####################################

默認安裝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登陸界面中出現服務器候選列表,說明修改正確



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM