今天因为服务器出了问题选择了重装。装完之后发现本地的navicat连不上数据库了。提示60错误。之前都是修改下mysql库user表中User=root这一行的Host改成%,表示允许任何主机连接。但是今天加完这个权限之后依旧不行。

想着可能是端口的问题。就查看了下端口占用情况和访问规则。

sudo iptables -L
##显示信息
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:https
DROP tcp -- anywhere anywhere tcp dpt:mysql
ACCEPT tcp -- anywhere anywhere tcp dpt:ftp-data
ACCEPT tcp -- anywhere anywhere tcp dpt:ftp
ACCEPT tcp -- anywhere anywhere tcp dpts:dnp:30000
ACCEPT icmp -- anywhere anywhere icmp echo-request

发现了mysql对应的这一条规则被DROP了。这打开就是本地连不上的原因了吧。然后删除这一条规则。(mysq这一条是第6行)

sudo iptables -D INPUT 6

这样就完成可以远程访问数据库了。