阿里云ecs上安装了mysql但是外网访问不了

查看:466
本文介绍了阿里云ecs上安装了mysql但是外网访问不了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

阿里云ecs上安装了mysql但是外网访问不了

步骤
使用yum安装mysql server
启动mysql
grant 一个用户 允许所有host访问
重起mysql

这是mysql库中的user表

mysql> select host,user from user;
+-------------------------+---------+
| host                    | user    |
+-------------------------+---------+
| %                       | dbadmin |
| %.%.%.%                 | icyfc   |
| 127.0.0.1               | root    |
| iz8vb8il84z4prxo5ljzqjz |         |
| iz8vb8il84z4prxo5ljzqjz | root    |
| localhost               |         |
| localhost               | root    |
+-------------------------+---------+

[root@iZ8vb8il84z4prxo5ljzqjZ ~]# netstat -tunpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      2630/php-fpm        
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      32007/mysqld        
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      2805/nginx          
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      15354/sshd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1555/master         
udp        0      0 172.26.13.175:123           0.0.0.0:*                               1464/ntpd           
udp        0      0 127.0.0.1:123               0.0.0.0:*                               1464/ntpd           
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               1464/ntpd           
udp        0      0 0.0.0.0:68                  0.0.0.0:*                               1060/dhclient       
[root@iZ8vb8il84z4prxo5ljzqjZ ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:mysql 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination  

解决方案

1 阿里云ECS有安全组防火墙.默认只开了ICMP,22,3389. 在服务器控制台找到 安全组-配置规则-添加安全组规则

2 如果是用root登录MySQL,在登陆后use mysql, user表root对应的localhost改为%

3 mysql默认只能自本机访问,在 /etc/mysql/mysql.conf.d/mysqld.cnf 里注释bind-address : #bind-address = 127.0.0.1
操作完成后重启mysql服务: service mysql restart

4 netstat -ntpl |grep 3306 检查是不是在监听状态

5 防火墙是否对 mysql 端口限制,设置防火墙

有以上5步应该没问题了

这篇关于阿里云ecs上安装了mysql但是外网访问不了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆