为了安全考虑,仅允许云主机本机(localhost)连接数据库,如果需要远程连接数据库,需要如下操作:
打开iptables 3306端口
# iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT# service iptables save #保存iptables规则
如下图:
![](https://i-blog.csdnimg.cn/blog_migrate/2dcbdb2f95a51367cd132dbd286b3b60.png)
数据库授权
远程连接新建一个帐号(帐号名不能为root)。
如:添加一个用户名为linuxeye,密码为123456,授权为% (%表示所有ip能连接,可以设置指定ip)对数据库所有权限,命令如下:
# mysql –uroot –pMySQL [(none)]> ; #授权语句,特别注意有分号MySQL [(none)]> flush privileges;MySQL [(none)]> exit; #退出数据库控制台,特别注意有分号
如下图:
![](https://i-blog.csdnimg.cn/blog_migrate/4ace7a79e2ad53b1b97cb3f7b6194bd0.png)