centos7 端口3306无法连接问题

centos7 端口3306无法连接问题,第1张

centos7 端口3306无法连接问题

MySQL建用户的时候会指定一个host,默认是127.0.0.1/localhost,那么这个用户就只能本机访问,其它机器用这个用户帐号访问会提示没有权限,host改为%,表示允许所有机器访问。


GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

允许任何ip以root用户以密码123456登录

flush privileges;立即生效

CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。


2、关闭firewall:
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl mask firewalld.service

3、安装iptables防火墙
yum install iptables-services -y

4.启动设置防火墙

# systemctl enable iptables
# systemctl start iptables

5.查看防火墙状态

systemctl status iptables

6编辑防火墙,增加端口
vi /etc/sysconfig/iptables #编辑防火墙配置文件
-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! #保存退出

7.重启配置,重启系统
systemctl restart iptables.service #重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动

此时,如果端口还是无法访问,就是阿里云的安全组没有添加。


添加自定义安全组,开放端口。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/588227.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存