navicat远程连接mysql出现1045问题解决!

Navicat连接mysql数据库报错:1045 - Access denied for user ‘root’@‘localhost’ (using password: YES)。

这是数据库权限的问题,workbench等也会同样报错

问题所在:未给root用户分配所有权限,本地客户端无权限登录root用户。

以root用户登录mysql,运行show grants for ‘user’@‘IP’;

show grants for ‘root’@‘192.168.170.136’;
ERROR 1141 (42000): There is no such grant defined for user ‘root’ on host ‘192.168.170.136’

show grants for ‘root’@‘localhost’;
±---------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
±---------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON . TO ‘root’@‘localhost’ IDENTIFIED BY PASSWORD ‘*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B’ WITH GRANT OPTION |
±---------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
通过上述两个查询语句的对比,说明root用户只给了本地服务器的访问权限,而没有给192.168.170.136客户端的访问权限。

也可以通过查询mysql的user表来查看用户权限:

select user,host from mysql.user;

±------±--------------+
| user | host |
±------±--------------+
| root | localhost |
±------±--------------+
1 rows in set (0.00 sec)
说明root用户只对localhost授予了访问权限。

解决方法:进行root用户的远程访问授权,可以授权到指定的客户端IP,也可以授权为所有IP都可访问(host值为%):

GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘root’ WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

flush privileges;
Query OK, 0 rows affected (0.00 sec)
select user,host,password from mysql.user;
±------±--------------±------------------------------------------+
| user | host | password |
±------±--------------±------------------------------------------+
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | % | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
±------±--------------±------------------------------------------+
2 rows in set (0.00 sec)
这样就ok了。

你可能感兴趣的:(navicat远程连接mysql出现1045问题解决!)