/var/www/html/phpmyadmin 或自定義路徑mysqli、mbstring、zip、gd、json、session複製 config.sample.inc.php 為 config.inc.php,編輯關鍵項:
$cfg['PmaAbsoluteUri'] = 'https://your-domain.com/phpmyadmin/';
$i = 0;
$i++;
$cfg['Servers'][$i]['host'] = 'localhost'; // 或 127.0.0.1
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['auth_type'] = 'cookie'; // 推薦:Cookie 認證
$cfg['Servers'][$i]['user'] = 'root'; // 預設用戶
$cfg['Servers'][$i]['password'] = ''; // 空密碼由登入頁輸入
$cfg['Servers'][$i]['only_db'] = ''; // 空 = 顯示所有資料庫
$cfg['Servers'][$i]['AllowNoPassword'] = false; // **生產必須 false**
# 修改 libraries/config.default.php(舊版)或 config.inc.php
$cfg['Servers'][$i]['AllowNoPassword'] = true; // 允許無密碼登入
⚠️ 警告:生產環境**嚴禁**啟用,極大安全風險!
$cfg['blowfish_secret'] = 'your-32-chars-random-string-here!'; // 32 字元以上隨機字串
用途:加密 Cookie 中的認證資訊。未設定會報錯:「配置文件現在需要絕密的短語密碼」。
生成方式:
# Linux 命令列
openssl rand -base64 32
# 或 PHP
php -r "echo base64_encode(random_bytes(32));"
$cfg['DefaultLang'] = 'zh_TW'; // 繁體中文
$cfg['ThemeDefault'] = 'pmahomme';
$i = 0;
// 伺服器 1:本地主庫
$i++;
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['verbose'] = '本地主庫';
// 伺服器 2:遠端從庫
$i++;
$cfg['Servers'][$i]['host'] = '192.168.1.100';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['verbose'] = '遠端從庫';
| 現象 | 原因 | 解決 |
|---|---|---|
| 「無法連線 MySQL 伺服器」 | host/socket/port 錯誤、MySQL 未啟動、防火牆 | 檢查 netstat -tlnp | grep 3306、systemctl status mysqld |
| 「配置文件需要 blowfish_secret」 | 未設定 $cfg['blowfish_secret'] | 設定 32+ 字元隨機字串 |
| 登入後空白/報錯 | PHP session 目錄不可寫、mbstring 未裝 | chmod 777 /var/lib/php/session、安裝擴展 |
| 匯入大 SQL 失敗 | upload_max_filesize/post_max_size/max_execution_time 過小 | 調整 php.ini、或用命令列 mysql < file.sql |
| 中文亂碼 | 連線字符集未設定 | 配置 $cfg['DefaultCharset'] = 'utf8';、MySQL 端設定 utf8mb4 |
AllowNoPassword = falseauth_type = 'cookie'(而非 config/http)blowfish_secret
# 下載單一 PHP 檔案即可使用
wget https://github.com/vrana/adminer/releases/download/v4.8.1/adminer-4.8.1.php
mv adminer-4.8.1.php /var/www/html/adminer.php
功能相近、無需配置、記憶體佔用極低、適合臨時除錯。