CentOS 7 -防火牆設置--安裝數據庫,遠程連接報錯--Can't connect to MySQL server on localhost (10061)


前提簡介:在CentOS 7 上安裝了mysql5.7版本,已設置了遠程訪問權限,但是其他服務器無法訪問到此Mysql,提示【Can't connect to MySQL server on localhost (10061)】。

懷疑是防火牆的原因,百度/必應了很多,一般防火牆都是【iptable】,修改配置也是在【/etc/init.d/iptables】里,無奈就是找不到配置文件,后台查看到CentOS 7版本不同於其他版本,防火牆有一些特別,這里說一下解決方法吧!

CentOS 7的防火牆,查看狀態:

[root@localhost sysconfig]# firewall-cmd --state
running

添加防火牆端口:

[root@localhost sysconfig]# firewall-cmd --zone=public --add-port=80/tcp --permanent      #添加80端口
success
[root@localhost sysconfig]# firewall-cmd --zone=public --add-port=3306/tcp --permanent     #添加3306端口,此為數據庫默認端口
success

命令含義:
–zone #作用域
–add-port=80/tcp #添加端口,格式為:端口/通訊協議
–permanent #永久生效,沒有此參數重啟后失效

執行后,重啟防火牆就生效了,再次遠程連接Mysql就可以了!

防火牆其他命令:

firewall-cmd --reload #重啟firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動
firewall-cmd --state #查看默認防火牆狀態(關閉后顯示notrunning,開啟后顯示running)

參考文章:https://www.linuxidc.com/Linux/2016-12/138979.htm

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM