mysql navicat 能连 程序不能连的情况

mysql_异常_01_Access denied for user 'root'@'192.168.1.13' (using password: YES)

 

一、异常现象

使用navicat premuim 连接 虚拟机mysql数据库时 ,抛出如下错误:

Access denied for user 'root'@'192.168.1.13' (using password: YES)

二、异常原因

Mysql 安装完毕后,默认会有'root'@'localhost'用户,这个用户只能在本机登录mysql。若需要远程登录,则需要以'root'@'%' 用户登录。

出现上图,是因为当前数据库中没有 'root'@'%'用户,或是此用户密码不对,因此需要创建这个用户或修改此用户密码

三、异常解决

在 mysql 服务器上使用root进行登录:

mysql -u root -p

然后执行如下命令:

(1) 创建用户并授权

1
2
3
4
5
6
# 创建 'root'@'%'用户
CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
 
# 授权
grant all  on *.* to 'root'@'%';
flush privileges;

  

  

(2)或者修改密码

1
alter user 'root'@'%' identified by 'root.';

  

然后再连接即可成功连接。

二、参考资料

1.解决mysql"Access denied for user'root'@'IP地址'"问题

2.关于远程访问mysql出现Access denied for user 'root'@'的解决方法

原文地址:https://www.cnblogs.com/zengpeng/p/14262236.html