ip连接mysql时报不能连接

 问题:springboot项目在用localhost连接mysql时没问题,但当localhost换成ip时出现

该问题:message from server: "Host 'DESKTOP-V8FMU6569' is not allowed to connect to this MySQL server"

意思是:该ip不能连接到mysql。

原因:mysql服务器在安装后,应该默认只能本地localhost才能连接。

解决:

 (1)有安装navicat的,打开找到myql数据库,里面有user表,把user表中的user为root的localhost改成%  。%代表通配,ip都可以访问,如下截图

(2)搞定后 cmd 进入自己mysql数据库

指令为:mysql->mysql-uroot -proot

  然后 mysql->flush privileges; 

(3)再去启动自己项目,搞定。

如果没有用navicat,cmd进入mysql数据库

mysql -uroot -proot>use mysql;

mysql>update user set host = '%' where user = 'root';

mysql->flush privileges; 

搞定。

 参考:https://blog.csdn.net/mao_mao37/article/details/104298661

  https://blog.csdn.net/chaozhiwang/article/details/104295879

猜你喜欢

转载自www.cnblogs.com/yiyezhiqiuwuchen/p/12373130.html