查看了下mysql的my.cnf配置文件,bind_address 和 skip_networking 都注销了,root用户的host也设置为%了,可是就是一直没法远程链接,出现113的问题。mysql
网上说是防火墙的问题,因而关闭防火墙sql
service firewalld stop (centos 7)ubuntu
问题得以解决!能够顺利地链接上了!vim
若是要启用iptables,centos 7 下没有iptables服务,要先安装centos
yum install iptables-services
安装后vim /etc/sysconfig/iptablestcp
*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那行添加spa
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
也就是rest
*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 #最后重启防火墙使配置生效code
systemctl enable iptables.service #设置防火墙开机启动blog
而后 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