Centos 下 can't connect mysql server 113

查看了下mysql的my.cnf配置文件,bind_address 和 skip_networking 都注销了,root用户的host也设置为%了,但是就是一直无法远程连接,出现113的问题。

网上说是防火墙的问题,于是关闭防火墙

service firewalld stop (centos 7)

问题得以解决!可以顺利地连接上了!

如果要启用iptables,centos 7 下没有iptables服务,要先安装

yum install iptables-services

安装后vim /etc/sysconfig/iptables

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

在22那行添加

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

也就是

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited 
-A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT

 

systemctl restart iptables.service #最后重启防火墙使配置生效

systemctl enable iptables.service #设置防火墙开机启动

然后 mysql远程就可以连接上了!

 

不能在最后一行添加,否则不生效!

 

 

Ubuntu 防火墙添加3306端口
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT  

 

关闭ubuntu中的iptables

iptables -F  
iptables -X    
iptables -Z    
iptables -P INPUT ACCEPT    
iptables -P OUTPUT ACCEPT    
iptables -P FORWARD ACCEPT    
modprobe -r ip_tables    

 开启iptables

modprobe ip_tables  

 

posted @ 2015-11-19 16:16  fover的天地  阅读(312)  评论(0)    收藏  举报