第一步:開啟MySQL用戶的遠(yuǎn)程訪問權(quán)限
mysql -u root -p mysql # 第1個mysql是執(zhí)行命令,第2個mysql是系統(tǒng)數(shù)據(jù)名稱
在MySQL控制臺執(zhí)行:
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
# root是用戶名,%代表任意主機(jī)止潮,'123456'指定的登錄密碼(這個和本地的root密碼可以設(shè)置不同的,互不影響)
flush privileges; # 重載系統(tǒng)權(quán)限
exit;
如果想允許用戶root從ip為192.168.137.99的主機(jī)連接到MySQL服務(wù):
grant all privileges on *.* to 'root'@'192.168.137.99' identified by '123456' with grant option;
flush privileges;
第二步:設(shè)置防火墻燥爷,讓 3306 端口對外可訪問
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
# 查看規(guī)則是否生效
iptables -L -n # 或者: service iptables status
FirewallD防火墻開放3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
命令含義:
- zone #作用域
- add-port=3306/tcp #添加端口,格式為:端口/通訊協(xié)議
- permanent #永久生效懦窘,沒有此參數(shù)重啟后失效
重啟防火墻
systemctl restart firewalld.service
---------------------
作者:LaooGao
來源:CSDN
原文:https://blog.csdn.net/u013257111/article/details/79063578
此時生產(chǎn)環(huán)境是不安全的前翎,遠(yuǎn)程管理之后應(yīng)該關(guān)閉端口,刪除之前添加的規(guī)則
iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
注意:上面iptables添加/刪除規(guī)則都是臨時的畅涂,如果需要重啟后也生效鱼填,需要保存修改:
service iptables save # 或者: /etc/init.d/iptables save
另外,
vi /etc/sysconfig/iptables # 加上下面這行規(guī)則也是可以的
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT