最新换了台机器,软件全部重新安装了一遍,在安装完MysqlServer赋予相应用户权限后当然也遇到了一些问题。
关于如何安装MysqlServer及遇到问题可以参考以前写的两篇博客。
在VM上安装完成MySQL—Server之后使用Navicat无法正常连接到服务。
使用cmd的telnet看了下检查了一下发现是服务没有开启端口访问。
下面可以使用两种方法解决解决这个问题。
1.关闭防火墙。最简单的方案,不做任何限制。但是防火墙没有了总觉得像是裸奔,虽然行但是总觉得少点啥。1
2systemctl stop firewalld
systemctl status firewalld
此时再次连接一下数据库,发现是连上的。
但即便如此还是建议采用较为安全的方式。
2.使用iptables进行开放端口。其实是在iptables防火墙中配置拦截规则。
查看端口是否可访问:telnet ip 端口号 (如本机的3306:telnet localhost 3306)
开放的端口位于/etc/sysconfig/iptables中
查看时通过 more /etc/sysconfig/iptables 命令查看
如果想开放端口(如:3306)
(1)通过vi /etc/sysconfig/iptables 进入编辑增添一条-A INPUT -p tcp -m tcp –dport 3306 -j ACCEPT 即可
(2)执行 /etc/init.d/iptables restart 命令将iptables服务重启
(3)保存 /etc/rc.d/init.d/iptables save
题外话:
1.刚买的电脑竟然进去cmd,连个telnet都没有,可以参考下一篇的《设置windows的telnet》。
2.另我用的CentOS7.3.1的时候使用iptables命令提示cannot found command,那是因为默认使用的是firewall作为防火墙,没有安装iptables,可以使用以下命令1
2
3
4
5systemctl stop firewalld
systemctl mask firewalld
yum install -y iptables
yum install iptables-services
然后就有iptables文件,就可以作配置
开启服务1
2
3
4systemctl start iptables.service
systemctl restart iptables.service // 重启防火墙使配置生效
systemctl enable iptables.service // 设置防火墙开机启动
其他命令:
检查是否安装了iptables1
2
3
4
5
6
7
8
9
10
11
12
13
14
15service iptables status
#安装iptables
yum install -y iptables
#升级iptables
yum update iptables
#安装iptables-services
yum install iptables-services
systemctl disable iptables #禁止iptables服务
systemctl stop iptables #暂停服务
systemctl enable iptables #解除禁止iptables
systemctl start iptables #开启服务
其实firewall和iptables都是防火墙,实现的原理不一样罢了,在这里不做多说。
原创不易,转载请注明出处!
加油!Coding For Dream!!
I never feared death or dying, I only fear never trying. –Fast & Furious