use mysql;
update user set host = '%' where user = 'root';
select host, user from user; flush privileges;
出错不管他
mysql> select host ,user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | admin |
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| localhost | debian-sys-maint |
| ubuntu | root |
+-----------+------------------+
关键是这一行:| % | root | %
表示可以允许任何机器访问。
此时远程还是连不上。
然后查看3306端口情况
使用nestat命令查看3306端口状态:
~# netstat -an | grep 3306
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
从结果可以看出3306端口只是在IP 127.0.0.1上监听,所以拒绝了其他IP的访问。
解决方法:修改/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