原因:my.cnf 中 bind-address = 127.0.0.1 限制只監聽本地。
# 找到 my.cnf(通常在 /etc/mysql/ 或 /etc/)
# 註釋掉 bind-address
#bind-address = 127.0.0.1
重啟 MySQL:service mysqld restart。
# 查看狀態
chkconfig --list | grep iptables
# 臨時關閉
/sbin/service iptables stop
生產環境建議僅開放 3306 埠而非完全關閉防火牆。
授權遠程訪問賬號:
-- 允許 root 從任意主機連接,密碼 root
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
-- 允許特定 IP
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY '123456' WITH GRANT OPTION;
執行後 FLUSH PRIVILEGES; 生效。