mysql怎么连接wpf mysql怎么连接到我的sql主机( 二 )


(using password: YES) 。
下面分析这类 ERROR 1045 (28000): Access denied for user'usera'@'localhost'错误出现的原因:
原因1 : 客户端远程访问的用户账号并未创建
检查 :
以管理员ROOT登录后,show grants for 'user'@’IP‘; 或者 select user from mysql.user; 确认用户账号是否存在 。
mysql show grants for 'jtsec'@'192.168.8.123';
ERROR 1141 (42000): There is no such grant defined for user 'jtsec' on host '192.168.8.123'
mysql
返回信息:ERROR 1141 (42000): There is no such grant defined for user 'jtsec' on host '192.168.8.123'
说明,没有jtsec用户,或者没有对jtsec用户进行在192.168.8.123远程访问的授权 。
mysql select user,host from mysql.user;
+-------+---------------+
| user| host|
+-------+---------------+
| root| localhost|
+-------+---------------+
1 rows in set (0.00 sec)
mysql
关于user记录数只有一条 , 是root , 并没有jtsec相关的记录,说明没有数据库中没有jtsec这个帐号 。
处理 :创建用户账号 。
mysqlgrant all privileges on *.* to 'jtsec'@'192.168.8.123' identified by 'jtsec' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql show grants for 'jtsec'@'192.168.8.123';
+---------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for jtsec@192.168.8.123|
+---------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'jtsec'@'192.168.8.123' IDENTIFIED BY PASSWORD '*0B4AB716B6BE11F89101577836F3016D8EEAA217' WITH GRANT OPTION |
+---------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql select user,host from mysql.user;
+-------+---------------+
| user| host|
+-------+---------------+
| jtsec | 192.168.8.157 |
| root| localhost|
+-------+---------------+
2 rows in set (0.00 sec)
mysql
原因2 : 用户账号存在,但未对其所在的客户端的IP进行远程访问授权允许
检查 :
以管理员ROOT登录后 show grants for 'user'@'IP';
mysql show grants for 'root'@'192.168.8.123';
ERROR 1141 (42000): There is no such grant defined for user 'root' on host '192.168.8.123'
mysql
返回信息:ERROR 1141 (42000): There is no such grant defined for user 'root' on host '192.168.8.123'
说明,没有root用户(因为是MySQL超级用户所以排除此种可能) , 或者没有对root用户进行在192.168.8.123远程访问的授权 。
我们来对比一下看,root用户本地访问的权限,则可查出:
mysql 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)
或者直接查询mysql的user用户表select user,host from mysql.user;,其中记录了每一个用户的权限信息
mysql select user,host from mysql.user;
+-------+---------------+
| user| host|
+-------+---------------+

推荐阅读