![无法连接到 RHEL 5.7 上的 MySQL 服务器](https://linux22.com/image/576425/%E6%97%A0%E6%B3%95%E8%BF%9E%E6%8E%A5%E5%88%B0%20RHEL%205.7%20%E4%B8%8A%E7%9A%84%20MySQL%20%E6%9C%8D%E5%8A%A1%E5%99%A8.png)
我有一个在 Red hat 5.7 上运行的标准 MySQL 服务器。我已编辑 /etc/my.cnf,以将绑定地址指定为服务器的公共 IP 地址。
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
# Disabling symbolic-links is recommended to prevent assorted security risks ;
# to do so, uncomment this line:
# symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
bind-address=171.67.88.25
port=3306
我还重启了防火墙
sudo /sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
/sbin/service iptables save
网络管理员已经为该框打开了端口 3306。从远程计算机(运行 Ubuntu 10.10,服务器运行 RHEL 5.7)连接时,我发出
mysql -u jeffrey -p --host=171.67.88.25 --port=3306 --socket=/var/lib/mysql/mysql.sock
但收到错误 2003 (HY000):无法连接到‘171.67.88.25’ (113) 上的 MySQL 服务器。
我注意到套接字文件 /var/lib/mysql/mysql.sock 是空白的。应该是这种情况吗?
更新
的结果netstat -an | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
的结果sudo netstat -tulpen
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 0 7602 3168/hpiod
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 27 7827 3298/mysqld
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 0 5110 2802/portmap
tcp 0 0 0.0.0.0:8787 0.0.0.0:* LISTEN 0 8431 3326/rserver
tcp 0 0 0.0.0.0:915 0.0.0.0:* LISTEN 0 5312 2853/rpc.statd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 0 7655 3188/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 0 7688 3199/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 0 8025 3362/sendmail: acce
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 0 7620 3173/python
udp 0 0 0.0.0.0:909 0.0.0.0:* 0 5300 2853/rpc.statd
udp 0 0 0.0.0.0:912 0.0.0.0:* 0 5309 2853/rpc.statd
udp 0 0 0.0.0.0:68 0.0.0.0:* 0 4800 2598/dhclient
udp 0 0 0.0.0.0:36177 0.0.0.0:* 70 8314 3476/avahi-daemon:
udp 0 0 0.0.0.0:5353 0.0.0.0:* 70 8313 3476/avahi-daemon:
udp 0 0 0.0.0.0:111 0.0.0.0:* 0 5109 2802/portmap
udp 0 0 0.0.0.0:631 0.0.0.0:* 0 7691 3199/cupsd
的结果sudo /sbin/iptables -L -v -n
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
6373 2110K RH-Firewall-1-INPUT all -- * * 0.0.0.0/0 0.0.0.0/0
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 RH-Firewall-1-INPUT all -- * * 0.0.0.0/0 0.0.0.0/0
Chain OUTPUT (policy ACCEPT 1241 packets, 932K bytes)
pkts bytes target prot opt in out source destination
Chain RH-Firewall-1-INPUT (2 references)
pkts bytes target prot opt in out source destination
572 861K ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
1 28 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmp type 255
0 0 ACCEPT esp -- * * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT ah -- * * 0.0.0.0/0 0.0.0.0/0
46 6457 ACCEPT udp -- * * 0.0.0.0/0 224.0.0.251 udp dpt:5353
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:631
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:631
782 157K ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 120 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:443
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:23
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
4970 1086K REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
的结果nmap -P0 -p3306 171.67.88.25
Host is up (0.027s latency).
PORT STATE SERVICE
3306/tcp filtered mysql
Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds
解决方案
当其他一切都失败时,转到 GUI! system-config-securitylevel
并添加端口 3306。全部完成!
答案1
我也无法远程登录到机器端口:
[bart@uk ~]$ telnet 171.67.88.25 3306
Trying 171.67.88.25...
iptables -L -v -n
请发布和的输出netstat -tulpen
。您可以尝试关闭防火墙吗?
答案2
您可以尝试在 [mysqld] 下添加块吗?
[mysqld]
bind-address=171.67.88.25
port=3306
答案3
检查 selinux 状态 (/etc/selinux/config)。要禁用 selinux,请设置 SELINUX=disabled 并重新启动服务器。