配置phpmyadmin使登入時可填寫IP管理多台MySQL 串連多個資料庫 自動登入

來源:互聯網
上載者:User

標籤:

一、如何設定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登陸介面中出現伺服器候選列表,說明修改正確

配置phpmyadmin使登入時可填寫IP管理多台MySQL 串連多個資料庫 自動登入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.