如果你的Mysql数据库安装在centos7的系统上,并且你的操作系统启用了防火墙。应用要访问mysql数据库,你有2个解决方案。
方案一:停止防火墙服务
方案二:在防火墙中添加策略,让应用能正常访问mysql服务端口
停止Centos7防火墙
查看防火墙运行状态[root@mysql ~]# firewall-cmd --state
running
停止防火墙服务[root@mysql ~]# systemctl stop firewalld.service禁止防火墙开机启动[root@mysql ~]# systemctl disable firewalld.service启动Centos7防火墙
查看防火墙运行状态[root@mysql ~]# firewall-cmd --state
not running
启动防火墙服务[root@mysql ~]# systemctl start firewalld.service配置防火墙开机启动[root@mysql ~]# systemctl enable firewalld.service访问Mysql服务测试
连接Mysql服务
[mysql@mysql ~]$ mysql -utony -ptony -h 192.168.112.131 -P 3306
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.112.131' (113)
主从复制连接测试[root@localhost] 15:23:46 [(no