centos 7中mysql开启远程及开启3306端口

1、开启远程访问:

进入mysql

查看系统用户表:

select user,host from user;

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

扫描二维码关注公众号,回复: 5125326 查看本文章

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 #设置防火墙开机启动

检查技巧:

1.排除网络或防火墙问题 

先看是否能ping通远程服务器,ping 192.168.1.211,如果不可以就是网络问题。然后,检查端口是否被防火墙挡住了,telnet 192.168.1.211 3306,如果连接失败,配置防火墙。
配置防火墙,开启3306端口

2.检查MySQL配置

如果开启了防火墙,telnet还是失败,通过netstat查看3306的端口状态:

netstat -apn|grep 3306
tcp6  0  0 127.0.0.1:3306  :::*  LISTEN    13524/mysqld

转载链接:https://blog.csdn.net/qq_34341290/article/details/78969485

                  https://blog.csdn.net/qq_35912734/article/details/78881539

猜你喜欢

转载自blog.csdn.net/SICAUliuy/article/details/83828971
今日推荐