本篇内容介绍了“怎么解决MySQL中的ERROR 1045 (28000)错误问题”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
一、错误描述:
错误如标题:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)。我用root@localhost授权登陆,然后给其中
一个用户授权,然后报如上错误:
[mysql@centos6-clone ~]$ mysql -u root -p
Enter password:
Your MySQL connection id is 2
Server version: 5.6.25-log MySQL Community Server (GPL)
mysql> grant all on *.* to 'fi'@'127.0.0.1' identified by "fi";
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
mysql> exit
Bye
按理来说,root@localhost是最高权限。居然不能给其他人授权。1045错误是授权拒绝。怎么办?
二、错误分析
查看下root权限:
mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA' |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
我们看root@localhost 有权限:ALL PRIVILEGES,但是没有WITH GRANT OPTION 语句,就是别人授权的权限。所以,不能授权的原因是:
没有这个WITH GRANT OPTION 语句。
三、错误解决
知道原因了,解决问题就很简单了。用另外一个方式登录root@127.0.0.1,然后给root@localhost授权,这样root@localhost 就可以给其他用户
授权了。
[mysql@centos6-clone ~]$ mysql -uroot -p -h227.0.0.1
Enter password:
mysql> SHOW GRANTS
-> ;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@127.0.0.1 |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY PASSWORD '*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
[mysql@centos6-clone ~]$ mysql -uroot -p
Enter password:
mysql> grant all on *.* to 'fo'@'%' identified by "fo";
Query OK, 0 rows affected (0.00 sec)
“怎么解决MySQL中的ERROR 1045 (28000)错误问题”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。