【解決】連接遠程的數據庫提示Can't connect to MySQL server (10060)

【解決】ERROR 2003 (HY000): Can't connect to MySQL server on "host" (10038)

 

鏈接遠程MySQL時報錯:

ERROR 2003 (HY000): Can’t connect to MySQL server ‘ip’ (10038)服務器

查看錯誤類型(Linux系統)tcp

perror 113
  • 1

結果以下: 
OS error code 113: No route to hostspa

致使此錯誤的緣由爲服務器端防火牆未開放MySQL程序使用的端口,默認爲3306,開放端口便可rest

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
  • 1

保存設置並重啓防火牆code

service iptables save
service iptables restart

 

Linux 設置開放3306端口解決方案

 

防火牆server

開啓: service iptables start 
關閉: service iptables stop ip


長久開關閉防火牆get

開啓: chkconfig iptables on 
關閉: chkconfig iptables off it

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT #開啓3306端口io

/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT #開啓80端口 

/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT #開啓22端口 

 

個人本機是Ubuntu 只輸入了上面的命令就能夠打開了

 

/etc/rc.d/init.d/iptables save #保存配置 

/etc/rc.d/init.d/iptables restart #重啓服務 

查看已開放端口 
/etc/init.d/iptables status 
結果以下 
Table: filter 
Chain INPUT (policy ACCEPT) 
num target prot opt source destination 
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 

3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 

相關文章
相關標籤/搜索