本文示範如何在已安裝 phpMyAdmin(以 WAMP 內建為例)環境中,新增遠端 MySQL 伺服器連線設定。
C:\wamp\apps\phpmyadmin4.1.14)。config 資料夾,將 config.sample.inc.php 複製並重命名為 config/config.inc.php。https://localhost/phpmyadmin/setup,依畫面填寫遠端主機資訊:host、user、password。config/config.inc.php 複製覆蓋至根目錄 config.inc.php(建議先備份原檔)。<?php
$i = 0;
$i++;
$cfg['Servers'][$i]['verbose'] = '85';
$cfg['Servers'][$i]['host'] = '172.163.25.85'; // 遠端資料庫主機
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['nopassword'] = true;
$cfg['Servers'][$i]['auth_type'] = 'config'; // 以設定檔認證
$cfg['Servers'][$i]['user'] = 'user2'; // 資料庫帳號
$cfg['Servers'][$i]['password'] = ''; // 密碼為空
$cfg['Servers'][$i]['AllowNoPassword'] = true; // 允許空密碼登入
$cfg['DefaultLang'] = 'en';
$cfg['ServerDefault'] = 1;
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
?>
| 參數 | 說明 |
|---|---|
auth_type | 認證方式:config=設定檔帳密、cookie=Cookie 表單、http=HTTP Basic Auth |
AllowNoPassword | 布林值,預設 false。設為 true 允許空密碼帳號登入(僅測試環境建議啟用) |
connect_type | tcp 強制 TCP/IP 連線(遠端必須),本機可用 socket |
extension | PHP 擴充套件:mysqli(推薦)或 mysql(已棄用) |
重複 $i++ 區塊即可新增多組伺服器設定,phpMyAdmin 介面左側下拉選單可切換。
auth_type=config 明文存放帳密,改用 cookie 模式。GRANT ALL ON *.* TO 'user'@'client_ip' IDENTIFIED BY 'password';