(Mysql)linux开启远程访问权限及防火墙开放3306端口
转发:https://blog.csdn.net/qq_37655695/article/details/78042824
3、授权法:
[java] view plain copy
mysql> USE MYSQL;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION //赋予任何主机访问以及修改所有数据的权限
例如,你想root用户使用root从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
如果你想允许用户root从ip为192.168.1.123的主机连接到mysql服务器,并使用root作为密码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.123'IDENTIFIED BY 'root' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES //修改生效
最后:
防火墙开放3306端口
1、打开防火墙配置文件
vi /etc/sysconfig/iptables
?
2、增加下面一
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
?
3、更改后的防火墙配置文件
[java] view plain copy
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -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 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
4、保存后重启防火墙
service iptables restart (操作系统高得话这个命令不适合就用) systemctl restart iptables
posted on 2019-09-18 14:33 shenzen_小白 阅读(686) 评论(0) 编辑 收藏 举报