centos7 打開mysql 3306端口並 設置外部訪問


mysql安裝后默認是localhost訪問,如果需要外部訪問可以設置一個新的賬號把host改為%,意味着所有ip均可以訪問

grant all privileges on *.* to 'outUser'@'%' identified by '12' with grant option

然后

flush privileges;

就可以使用outUser賬戶密碼12來外部訪問,有的時候無法訪問需要打開防火牆開放端口

centos 7 中使用的是firewall-cmd命令

# firewall-cmd --list-all-zones    #查看所有的zone信息

# firewall-cmd --get-default-zone     #查看默認zone是哪一個

# firewall-cmd --zone=internal --change-zone=p3p1  #臨時修改接口p3p1所屬的zone為internal

# firewall-cmd --add-service=http    #暫時開放http

# firewall-cmd --permanent --add-service=http  #永久開放http

# firewall-cmd --zone=public --add-port=80/tcp --permanent  #在public中永久開放80端口

# firewall-cmd --permanent --zone=public --remove-service=ssh   #從public zone中移除服務

# firewall-cmd --reload   #重新加載配置

  打開3306端口

firewall-cmd --add-port=3306/tcp --permanent

  ok

 


免責聲明!

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



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