telnet 数据库发现不通后 查看vps的端口开放
netstat -antp | grep 3306
确认是0.0.0.0监听即可,若是127.0.0.1需要修改mysql配置
Solution:进入到mysql的配置文件所在目录(/etc/mysql/my.cnf)
找到文件中如下内容:
# Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 127.0.0.1
将bind-address注释掉,或者改成客户端主机IP
如果是0.0.0.0需要修改防火墙
添加规则,打开3306端口
- iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
查看规则是否生效
- iptables -L -n
上面使用iptables添加/删除规则都是临时的,如果需要重启也生效,就要保存修改
- service iptables save //或者 /etc/init.d/iptables save
例外一种方式也可以实现:
- vi /etc/sysconfig/iptables //打开配置文件
- -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT //添加这条规则
然后qw
- service iptables restart//重启