?
This document uses PHP Chinese website manual Release
下載phpmyadmin
配置phpmysql的配置文件
所有庫有賬號通過遠(yuǎn)程連接MySQL(mysql的grant授權(quán))
登錄測試(如果有做數(shù)據(jù)庫的主從要檢查用戶授權(quán),防止數(shù)據(jù)的不一致)
Linux版本于內(nèi)核號 CentOS release 6.5 (Final) 2.6.32-431.el6.x86_64 PHP版本 5.3.28 Phpmyadmin版本 phpMyAdmin-4.4.15-all-languages MySQL多實(shí)例 192.168.0.200:3307和192.168.0.200:3308(其中3307為master 3308為slave)
通過修改 phpmyadmin/libraries/config.default.php
大概在805行的$cfg['AllowArbitraryServer'] = true;
# allow login to any user entered server in cookie based authentication,效果如下圖:
進(jìn)行登錄,當(dāng)然這種方式依然得方法一中第四步的授權(quán),這里就不在贅述。(此方法測試未成功,繼續(xù)關(guān)注)
缺點(diǎn):登陸操作比較繁瑣,而且切換服務(wù)器時須首先退出當(dāng)前所登陸的服務(wù)器
到https://www.phpmyadmin.net/downloads/
下載phpMyAdmin-4.4.15-all-languages
,解壓到網(wǎng)站根目錄下重命名為phpmyadmin
cp config.sample.inc.php config.inc.php
復(fù)制根目錄下的config.sample.inc.php
為config.inc.php
,使用 sed -i '22,34s#^#//#g'
config.inc.php使用sed命令注釋掉之前相關(guān)行并編輯這個文件,添加一個$hosts數(shù)組和一個for循環(huán)
// /* // * First server // */ // $i++; // /* Authentication type */ // $cfg['Servers'][$i]['auth_type'] = 'cookie'; // /* Server parameters */ // $cfg['Servers'][$i]['host'] = 'localhost'; // $cfg['Servers'][$i]['connect_type'] = 'tcp'; // $cfg['Servers'][$i]['compress'] = false; // /* Select mysql if your server does not have mysqli */ // $cfg['Servers'][$i]['extension'] = 'mysqli'; // $cfg['Servers'][$i]['AllowNoPassword'] = false; $hosts = array( '1'=>array('host'=>'192.168.0.200','user'=>'phpmyadmin','password'=>'phpmyadmin','port'=>3307), '2'=>array('host'=>'192.168.0.200','user'=>'phpmyadmin','password'=>'phpmyadmin','port'=>3308) ); for($i=1,$j=count($hosts);$i<=$j;$i++){ /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ $cfg['Servers'][$i]['host'] = $hosts[$i]['host']; //修改host $cfg['Servers'][$i]['port'] = $hosts[$i]['port']; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; /* Select mysqli if your server has it */ $cfg['Servers'][$i]['extension'] = 'mysqli'; $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'; }
更改完成后刷新登錄頁面,發(fā)現(xiàn)是不是多了些什么?我們可以選擇不同的服務(wù)器(或者不同的端口)進(jìn)行登錄了。
由于這邊192.168.0.200:3307為master,我們在3307端口上進(jìn)行授權(quán):grant all privileges on *.* to 'phpmyadmin'@'192.168.0.%' identified by 'phpmyadmin' WITH GRANT OPTION;
如果3307和3308已經(jīng)實(shí)現(xiàn)了主從同步,那么我們可以通過用戶名為phpmyadmin和密碼為 phpmyadmin登錄了,但是這樣授權(quán)是十分不安全的。建議在生產(chǎn)環(huán)境中不要這么粗暴的使用,另外我們需要對slave實(shí)例進(jìn)行回收權(quán)限,登錄192.168.0.3308,操作如下:REVOKE INSERT,ALTER,CREATE,DELETE,DROP,UPDATE ON *.* FROM 'phpmyadmin'@'192.168.0.%'
另可以通過show privileges;查看更多授權(quán)權(quán)限以及相關(guān)作用。
效果如下
相關(guān)的增刪改操作提示無權(quán)限,防止用戶誤操作引起的主從同步數(shù)據(jù)的不一致。(這里也可以配置mysql庫的主從不同步,然后分別在3307和3308端口上授予用戶不同的權(quán)限即可)。
優(yōu)點(diǎn):登陸操作簡便,登陸后切換服務(wù)器無須退出當(dāng)前連接。
方法一、方法二不可混用,如果按照方法一進(jìn)行了操作,那么方法二將無法生效