故障现象
- 客户端报
ERROR 2003 (HY000): Can't connect to MySQL server on 'host' (111) - 应用层连接池全部失败,服务不可用
telnet host 3306连接拒绝
常见根因
- MySQL 服务未启动或已崩溃
- 防火墙 / 安全组拦截了 3306 端口
bind-address配置为 127.0.0.1,拒绝远程连接- 端口被其他进程占用
解决步骤
- 检查 MySQL 进程是否运行
systemctl status mysqld ps -ef | grep mysqld
- 若服务已停止,尝试启动并查看错误日志
systemctl start mysqld tail -100 /var/log/mysqld.log
- 检查端口监听
ss -tlnp | grep 3306 netstat -tlnp | grep 3306
- 检查防火墙规则(CentOS / iptables)
firewall-cmd --list-ports # 若需放行: firewall-cmd --permanent --add-port=3306/tcp && firewall-cmd --reload
- 检查 my.cnf 中 bind-address 配置
# /etc/my.cnf 或 /etc/mysql/mysql.conf.d/mysqld.cnf # 改为 0.0.0.0 允许所有来源(生产注意配合白名单) bind-address = 0.0.0.0