本文主要是介绍centos 7 下安装mysql 远程连接出现10038错误如何解决,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
转载:http://www.codegong.com/document/19 非常感谢
转载请注明来自 代码功 ,本文标题: centos 7 下安装mysql 远程连接出现10038错误如何解决, 转载请保留本声明!
centos7 安装完mysql后想使用远程连接mysql进行管理,但是并没有那么简单 cant connect to mysql server on 10038
对没错,肯定会出现这样那样的问题,解决方案
首先 设置远程访问权限 在mysql中执行语句
grant all privileges on *.* to 'root'@'%' identified by 'youpassword' with grant option;
*.* 允许远程访问的IP地址 .表示所有IP都可以根据root用户进行访问
youpassword就是mysql数据库密码
flush privileges; //刷新MySQL的系统权限相关表
quit; // 退出mysql
记得重启mysql centos7下如何重启?
service mysql restart #重启mysql命令
好了,试试可以连接成功吗?结果是否定的,还是不行,怎么办?防火墙,对
但是centos7的防火墙默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。
1、关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
2、iptables防火墙(这里iptables已经安装,下面进行配置,如果没有安装可先安装防火墙)
#先检查是否安装了iptables
service iptables status
#安装iptables
yum install -y iptables
#升级iptables(安装的最新版本则不需要)
yum update iptables
#安装iptables-services
yum install iptables-services
iptables没有问题后执行下面的命令
vi /etc/sysconfig/iptables #编辑防火墙配置文件
这时候会进入vi编辑,你会看到里面的配置信息
# sampleconfiguration for iptables service
# you can edit thismanually or use system-config-firewall
# please do not askus to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT[0:0]
:OUTPUT ACCEPT[0:0]
-A INPUT -m state--state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -jACCEPT
-A INPUT -i lo -jACCEPT
-A INPUT -p tcp -mstate --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -jACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080-j ACCEPT
-A INPUT -j REJECT--reject-with icmp-host-prohibited
-A FORWARD -jREJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #保存退出
当然,里面的这三行是没有的,把下面的三行配置添加到里面,如果编辑vi不会可以百度,实际上按i就进入编辑模式了,具体操作可以百度
-A INPUT -p tcp -mstate --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -jACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080-j ACCEPT
完成后执行下面的命令
systemctl restart iptables.service #最后重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动
然后再看看,mysql是否已经连接,到这里后我已经成功连接
这篇关于centos 7 下安装mysql 远程连接出现10038错误如何解决的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!