昨天在虚拟机上装了MySQL数据库,今天打算用Navicat for MySQL工具连下,结果连接不上。
使用本地Navicat for MySQL工具连接虚拟机上的MySQL数据库:

解决方案
1、首先使用xshell工具连上虚拟机服务器,输入命令:# mysql -u root -p,然后回车,输入密码后回车进入mysql命令行

2、敲入命令:# use mysql; 回车

3、输入select user, authentication_string, host from user;回车,看到host中只有localhost主机,所以需要将要连接此MySQL的主机IP添加到这里:

4、输入授权远程访问命令:grant all privileges on *.* to 'root'@'192.168.xxx.xxx' identified by '123456' with grant option;

然后输入flush privileges;命令。
如果此处grant命令出错,

参考:https://www.cnblogs.com/lqinghua/p/11641430.html 解决,一般是密码策略问题。
也可以参考:https://www.cnblogs.com/benjamin77/p/10234547.html
5、再次输入select user, authentication_string, host from user;回车,可以看到host中已有新加的IP。

接下来再次尝试用本机Navicat for MySQL连接虚拟机MySQL,如果还连接不上,需要关闭虚拟机的防火墙,
详见:https://www.jianshu.com/p/d58c3307de51
本文参考资料:https://zhidao.baidu.com/question/871934886095716972.html

喜欢的朋友记得点赞、收藏、关注哦!!!