CentOS的MySQL远程连接ERROR 2003 (HY000):Can't connect to MySQL server on'XXXXX'(111) 的问题
今天在CentOS7虚拟机上安装了mysql,想要在宿主机上远程连接,结果一直报错,就百度了原因,这里分享一篇博客以及自己的一点知识。
引用:
问题描述:
以上是博主分享的各种问题,我经过了上边所有排查,结果依然连接不上。突然灵机一动就想到了系统防火墙,这么重要的细节自己竟然忘掉了,centOS上的防火墙还开着呢,怎么能远程连接。然后关闭防火墙就实现了完美连接。
这里附上centos有关防火墙的操作:
CentOS6.5查看防火墙的状态:
1 | [linuxidc@localhost ~]$service iptable status |
显示结果:
1 2 3 4 5 | [linuxidc@localhost ~]$service iptable status Redirecting to /bin/systemctl status iptable.service ● iptable.service Loaded: not -found (Reason: No such file or directory) Active: inactive (dead) --表示防火墙已经关闭 |
CentOS 6.5关闭防火墙
1 2 | [root@localhost ~]#servcie iptables stop --临时关闭防火墙 [root@localhost ~]#chkconfig iptables off --永久关闭防火墙 |
CentOS 7.2关闭防火墙
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
1 2 | [root@localhost ~]#firewall-cmd --state not running |
检查防火墙的状态:
从centos7开始使用systemctl来管理服务和程序,包括了service和chkconfig。
1 2 | [root@localhost ~]#systemctl list-unit-files|grep firewalld.service --防火墙处于关闭状态 firewalld.service disabled |
或者
1 2 3 4 | [root@localhost ~]#systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) |
关闭防火墙:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
1 2 | [root@localhost ~]#systemctl stop firewalld.service [root@localhost ~]#systemctl disable firewalld.service |
1 2 3 4 5 6 7 8 | 启动一个服务:systemctl start firewalld.service 关闭一个服务:systemctl stop firewalld.service 重启一个服务:systemctl restart firewalld.service 显示一个服务的状态:systemctl status firewalld.service 在开机时启用一个服务:systemctl enable firewalld.service 在开机时禁用一个服务:systemctl disable firewalld.service 查看服务是否开机启动:systemctl is -enabled firewalld.service;echo $? 查看已启动的服务列表:systemctl list-unit-files|grep enabled |
CentOS6.5查看防火墙的状态:
1 | [linuxidc@localhost ~]$service iptable status |
显示结果:
1 2 3 4 5 | [linuxidc@localhost ~]$service iptable status Redirecting to /bin/systemctl status iptable.service ● iptable.service Loaded: not -found (Reason: No such file or directory) Active: inactive (dead) --表示防火墙已经关闭 |
CentOS 6.5关闭防火墙
1 2 | [root@localhost ~]#servcie iptables stop --临时关闭防火墙 [root@localhost ~]#chkconfig iptables off --永久关闭防火墙 |
CentOS 7.2关闭防火墙
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
1 2 | [root@localhost ~]#firewall-cmd --state not running |
检查防火墙的状态:
从centos7开始使用systemctl来管理服务和程序,包括了service和chkconfig。
1 2 | [root@localhost ~]#systemctl list-unit-files|grep firewalld.service --防火墙处于关闭状态 firewalld.service disabled |
或者
1 2 3 4 | [root@localhost ~]#systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) |
关闭防火墙:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
1 2 | [root@localhost ~]#systemctl stop firewalld.service [root@localhost ~]#systemctl disable firewalld.service |
1 2 3 4 5 6 7 8 | 启动一个服务:systemctl start firewalld.service 关闭一个服务:systemctl stop firewalld.service 重启一个服务:systemctl restart firewalld.service 显示一个服务的状态:systemctl status firewalld.service 在开机时启用一个服务:systemctl enable firewalld.service 在开机时禁用一个服务:systemctl disable firewalld.service 查看服务是否开机启动:systemctl is -enabled firewalld.service;echo $? 查看已启动的服务列表:systemctl list-unit-files|grep enabled |
CentOS6.5查看防火墙的状态:
1 | [linuxidc@localhost ~]$service iptable status |
显示结果:
1 2 3 4 5 | [linuxidc@localhost ~]$service iptable status Redirecting to /bin/systemctl status iptable.service ● iptable.service Loaded: not -found (Reason: No such file or directory) Active: inactive (dead) --表示防火墙已经关闭 |
CentOS 6.5关闭防火墙
1 2 | [root@localhost ~]#servcie iptables stop --临时关闭防火墙 [root@localhost ~]#chkconfig iptables off --永久关闭防火墙 |
CentOS 7.2关闭防火墙
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
1 2 | [root@localhost ~]#firewall-cmd --state not running |
检查防火墙的状态:
从centos7开始使用systemctl来管理服务和程序,包括了service和chkconfig。
1 2 | [root@localhost ~]#systemctl list-unit-files|grep firewalld.service --防火墙处于关闭状态 firewalld.service disabled |
或者
1 2 3 4 | [root@localhost ~]#systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) |
关闭防火墙:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
1 2 | [root@localhost ~]#systemctl stop firewalld.service [root@localhost ~]#systemctl disable firewalld.service |
1 2 3 4 5 6 7 8 | 启动一个服务:systemctl start firewalld.service 关闭一个服务:systemctl stop firewalld.service 重启一个服务:systemctl restart firewalld.service 显示一个服务的状态:systemctl status firewalld.service 在开机时启用一个服务:systemctl enable firewalld.service 在开机时禁用一个服务:systemctl disable firewalld.service 查看服务是否开机启动:systemctl is -enabled firewalld.service;echo $? 查看已启动的服务列表:systemctl list-unit-files|grep enabled |