1. 修改密码:
在navicat中按F6,运行:
use mysql;
UPDATE user SET Password = PASSWORD('你的新密码') WHERE user = 'root';
FLUSH PRIVILEGES;
这一步一定要有
如果没有
Password
这个字段的话,在mysql5.7中,Password
改成了authentication_string
。MySQL安装好之后默认是没有密码的,账号是root
参考这里:http://blog.csdn.net/qq_34562093/article/details/74370205
![](https://img.haomeiwen.com/i5261083/ff1cc9296ce9a8a4.png)
2.在本地访问服务器的数据库:
a. 此时在本机的Navicat连接服务器的数据库:
![](https://img.haomeiwen.com/i5261083/b7d1d30f4a51b4ef.png)
b. 那就执行:
update user set Host = '%' where User = 'root';
flush privileges;
mysql> update user set Host = '%' where User = 'root';
1062 - Duplicate entry '%-root' for key 'PRIMARY'
mysql> flush privileges;
Query OK, 0 rows affected
mysql>
如何上面的方法不行,那就直接用Navicat,在mysql.user表里,把红框内,从【localhost】改为【%】,然后重启MySQL即可连接成功
![](https://img.haomeiwen.com/i5261083/7333323340f228c3.png)
![](https://img.haomeiwen.com/i5261083/1b5859a723ed19e7.png)
网友评论