首页 > 代码库 > 连接MySQL数据常见问题

连接MySQL数据常见问题

 

错误信息1 :ERROR 1045 (28000): Access denied for user ‘usera‘@‘localhost‘ (using password:YES)错误信息2  :ERROR 1045 (28000): Access denied for user ‘usera‘@‘localhost‘ (using password:NO) 

 

总结

总结:对于 ERROR 1045 (28000): Access denied for user ‘root‘@‘127.0.0.1‘  此类错误返回时, (using password: ?)中?的关键字是YES还是NO,关键不在于用户是否存在,密码是否正确,它的结果取决于登录时,用户对于密码有没有字符串的输入,
如果没有,MySQL数据库验证后,若出错返回此类信息,则应是 (using password: NO),若用户对密码有字符串的输入,返回的则是(using password: YES)。

 

原因1 : 客户端远程访问的用户账号并未创建

 

检查

以管理员ROOT登录后,show grants for user@’IP‘; 或者 select user from mysql.user; 确认用户账号是否存在。mysql> show grants for test@127.0.0.1;ERROR 1141 (42000): There is no such grant defined for user test on host 127.0.0.1mysql>返回信息:ERROR 1141 (42000): There is no such grant defined for user test on host 127.0.0.1说明,没有jtsec用户,或者没有对jtsec用户进行在192.168.8.123远程访问的授权。

解决

mysql>  grant all privileges on *.* to test@127.0.0.1 identified by test with grant option;mysql> flush privileges;mysql> show grants for test@127.0.0.1;mysql> select user,host from mysql.user;

 

原因2 : 用户账号存在,但未对其所在的客户端的IP进行远程访问授权允许

 

检查

以管理员ROOT登录后 show grants for user@IP;mysql> show grants for root@127.0.0.1;ERROR 1141 (42000): There is no such grant defined for user root on host 127.0.0.1返回信息:ERROR 1141 (42000): There is no such grant defined for user root on host 127.0.0.1说明,没有root用户,或者没有对root用户进行在127.0.0.1远程访问的授权。mysql> show grants for root@localhost;或者直接查询mysql的user用户表select user,host from mysql.user;mysql> select user,host from mysql.user;

 

解决

进行root用户的远程访问授权,可以授权到指定的客户端IP,也可以授权为所有IP都可访问(host值为%)。授权为所有IP都使用用户root,密码root,来远程访问数据库mysql> GRANT ALL PRIVILEGES ON *.* TOroot@% IDENTIFIED BY root WITH GRANT OPTION;mysql> flush privileges;再次进行授权的查询mysql> show grants for root@%;再次查询授权表记录mysql> select user,host,password from mysql.user;
注意:mysql5.7用下面这条语句查询mysql
> select user,host,authentication_string from mysql.user;

 

原因3 : 用户账号授权访问的密码不正确

 

检查

以管理员ROOT登录后, select user,host, authentication_string  from mysql.user;mysql> select user,host, authentication_string from mysql.user;

 

解决

使用正确的访问密码进行访问即可。

 

连接MySQL数据常见问题