阿里云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步应该没问题了