錯誤碼 **110 = Connection timed out**,代表 **TCP 封包無法到達目標埠**,最常見原因是**防火牆攔截**。
netstat -ntlp | grep 3306
# 或
ss -ntlp | grep 3306
telnet mysql_host 3306
nc -zv mysql_host 3306
# iptables
iptables -L -n | grep 3306
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
service iptables save
# firewalld (CentOS 7+)
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload
# ufw (Ubuntu)
ufw allow 3306/tcp
| 原因 | 檢查方式 | 解決 |
|---|---|---|
| MySQL 未啟動 | systemctl status mysqld | systemctl start mysqld |
| bind-address 錯誤 | grep bind-address /etc/my.cnf | 設為 0.0.0.0 或註解 |
| skip-networking 開啟 | grep skip-networking /etc/my.cnf | 註解掉 |
| SELinux 阻擋 | getsebool -a | grep mysql | setsebool -P mysql_connect_any 1 |
排查順序: 服務狀態 → 埠監聽 → 本機連線 → 防火牆/安全組 → 網路路由 → MySQL 配置。錯誤 110 **90% 是防火牆**,優先檢查。