centos7 開放3306埠並可以遠端訪問
一.防火牆配置
CentOS 7.0預設使用的是firewall作為防火牆,這裡改為iptables防火牆。
1、關閉firewall:
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl mask firewalld.service
2、安裝iptables防火牆
yum install iptables-services -y
3、啟動設定防火牆
# systemctl enable iptables
# systemctl start iptables
4、檢視防火牆狀態
systemctl status iptables
5、編輯防火牆,增加埠
vi /etc/sysconfig/iptables #編輯防火牆配置檔案
-A INPUT -m state --state NEW -m tcp -p tcp --dport 20 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
:wq! #儲存退出
6、重啟配置,重啟系統
systemctl restart iptables.service #重啟防火牆使配置生效
systemctl enable iptables.service #設定防火牆開機啟動
二.開啟遠端訪問
命令列進MYSQL
執行這個
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
然後再執行
FLUSH PRIVILEGES;
上面表示任何IP下,使用root使用者,123456為密碼均可訪問所有資料庫