預設 MySQL 的 root 僅允許本機登入。若要讓本機的 phpMyAdmin 管理遠端資料庫,需完成三步驟:建立遠程帳號 → 授權 → 修改 phpMyAdmin 設定。
-- 僅允許特定 IP 連線
CREATE USER 'remote_user'@'203.0.113.10' IDENTIFIED BY 'strong_password';
-- 或允許任意 IP(% 為萬用字元,生產環境慎用)
CREATE USER 'remote_user'@'%' IDENTIFIED BY 'strong_password';
-- 授予指定資料庫所有權限
GRANT ALL PRIVILEGES ON `target_db`.* TO 'remote_user'@'203.0.113.10';
-- 套用權限變更
FLUSH PRIVILEGES;
mysql -h 203.0.113.10 -u remote_user -p
若能成功登入,代表帳號與防火牆設定無誤。
假設:
192.168.1.1(存取網址 https://192.168.1.1/phpmyadmin)192.168.1.2,帳號 admin,密碼 123456192.168.1.1 的網站目錄libraries/config.default.php(或 config.inc.php):$cfg['PmaAbsoluteUri'] = 'https://192.168.1.1/phpmyadmin';
$cfg['Servers'][$i]['host'] = '192.168.1.2'; // 遠端 MySQL IP
$cfg['Servers'][$i]['user'] = 'admin'; // 遠端帳號
$cfg['Servers'][$i]['password'] = '123456'; // 遠端密碼
$cfg['Servers'][$i]['auth_type'] = 'config'; // 直接帶入帳密,免輸入
$cfg['Servers'][$i]['connect_type'] = 'tcp'; // 強制 TCP 連線
https://192.168.1.1/phpmyadmin 即可直接管理遠端資料庫*.*REQUIRE SSL 於 GRANT 子句中完成上述設定,即可在本地透過圖形介面輕鬆管理遠端 MySQL。