查看了下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