centos 防火墙 3306(centos防火墙设置与端口开放的方法)

CentOS7和CentOS6怎样开启MySQL远程访问

1.开放mysql访问端口3306

修改防火墙配置文件

vi/etc/sysconfig/iptables

加入端口配置注意:增加的开放3306端口的语句一定要在icmp-host-prohibited之前

-A INPUT-m state--state NEW-m tcp-p tcp--dport 3306-j ACCEPT

重新加载规则

service iptables restart

默认mysql的用户是没有远程访问的权限的,因此当程序跟数据库不在同一台服务器上时,我们需要开启mysql的远程访问权限。

主流的有两种方法,改表法和授权法。

相对而言,改表法比较容易一点,个人也是比较倾向于使用这种方法,因此,这里只贴出改表法

2.修改mysql库里的host

登录mysql;

use mysql

update user set host=‘%‘ where user=‘root‘ and host=‘localhost‘;

记得一定还得修改密码,因为这时密码已失效,虽然本地还可以原密码登录,可远程改了host后还是没法访问

UPDATE user SET password=password("root") WHERE user=‘root‘;

flush privileges;

3.重启mysql,远程就可以访问了

service mysqld restart;

CentOS7开启MySQL远程访问

CentOS7这个版本的防火墙默认使用的是firewall,与之前的版本使用iptables不一样。按如下方便配置防火墙:

1、关闭防火墙:sudo systemctl stop firewalld.service

2、关闭开机启动:sudo systemctl disable firewalld.service

3、安装iptables防火墙

执行以下命令安装iptables防火墙:sudo yum install iptables-services

?

4、配置iptables防火墙,打开指定端口(CentOS6一样)

5、设置iptables防火墙开机启动:sudo systemctl enable iptables

6、之后的和CentOS6一样

CentOS下防火墙的基本操作命令

CentOS配置防火墙操作实例(启、停、开、闭端口):

注:防火墙的基本操作命令:

查询防火墙状态:

[root@localhost~]# service iptables status

停止防火墙:

[root@localhost~]# service iptables stop

启动防火墙:

[root@localhost~]# service iptables start

重启防火墙:

[root@localhost~]# service iptables restart

永久关闭防火墙:

[root@localhost~]# chkconfig iptables off

永久关闭后启用:

[root@localhost~]# chkconfig iptables on

CentOS7和CentOS6怎样开启MySQL远程访问

标签:操作启动top基本操作命令tedandblecentos7远程

centos出现“FirewallD is not running”怎么办

方法/步骤

执行firewall-cmd--permanent--zone=public--add-port=3306/tcp,提示FirewallD is not running,如下图所示。

通过systemctl status firewalld查看firewalld状态,发现当前是dead状态,即防火墙未开启。

通过systemctl start firewalld开启防火墙,没有任何提示即开启成功。

再次通过systemctl status firewalld查看firewalld状态,显示running即已开启了。

5

如果要关闭防火墙设置,可能通过systemctl stop firewalld这条指令来关闭该功能。

6

再次执行执行firewall-cmd--permanent--zone=public--add-port=3306/tcp,提示success,表示设置成功,这样就可以继续后面的设置了。

centos7怎么永久关闭防火墙

1、首先需要将xshell软件打开并连接到centos主机,然后输入命令“systemctl status firewalld.service”并按下回车键。

2、然后在下方可以查看得到“active(running)”,此时说明防火墙已经打开了。

3、在命令行中输入systemctl stop firewalld.service命令,进行关闭防火墙。

4、然后再使用命令systemctl status firewalld.service,在下方出现disavtive(dead),这样就说明防火墙已经关闭。

5、再在命令行中输入命令“systemctl disable firewalld.service”命令,即可永久关闭防火墙。

阅读剩余
THE END