我司上的慧林主機系統,因自帶phpmyadmin版本較低,換成Phpmyadmin4.0,需要修改相關配置以方便管理多臺服務器的mysql數據庫。
1.將phpmyadmin根目錄下的config.sample.inc.php文件備份,以便修改錯誤時恢復原樣;
2.將config.sample.inc.php改名為config.inc.php;
3.修改config.inc.php文件里相關內容:
$hosts = array(
'1'=>array("host"=>"192.168.0.1","user"=>"root","password"=>"123456"),
'2'=>array("host"=>"192.168.0.2","user"=>"root","password"=>"567890")
);
for($i=1;$i<=count($hosts);$i++){
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = $hosts[$i]['host'];
$cfg['Servers'][$i]['user'] = $hosts[$i]['user']; //修改用戶名
$cfg['Servers'][$i]['password'] = $hosts[$i]['password']; //密碼
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
改后保存,打開phpmyadmin主頁面登錄,發現報錯:

原來,服務器上mysql 數據庫root賬戶默認不支持遠程連接,那么,還得配置mysql讓root賬戶支持遠程連接。
打開mysql命令行窗口,執行
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;
其中'%'就代表任意主機,當然,你也可以改成指定遠程服務器IP,例如:
grant all privileges on *.* to 'root'@'192.168.10.168' identified by '123456' with grant option;
flush privileges;
修改好,查看root用戶情況,可以看到支持%了。
