微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Mysql 5.5 源码安装后创建用户报错"ERROR 1045 (28000): Access denied for user"

安装MySQL后,root用户可设置密码登录,其他新建的用户不能通过密码登录,只能不输入密码登录,而且对新建用户的授权均无效。


--创建一个库和用户
MysqL> create database fire;
Query OK, 1 row affected (0.00 sec)

MysqL> create user neo identified by 'MysqL#2015';
Query OK, 0 rows affected (0.00 sec)

MysqL> grant select,create,update,delete on fire.* to neo;
Query OK, 0 rows affected (0.00 sec)

MysqL> flush privileges;
Query OK, 0 rows affected (0.00 sec)

--使用新用户登录报错

[root@localhost data]# ./bin/MysqL -u neo -p"MysqL#2015"
ERROR 1045 (28000): Access denied for user 'neo'@'localhost' (using password: YES)

--但是不输入密码却可以登录

[root@localhost software]# ./bin/MysqL -uneo
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 11
Server version: 5.5.48-log production environment

copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered Trademark of Oracle Corporation and/or its
affiliates. Other names may be Trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MysqL> show grants;
+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
1 row in set (0.00 sec)

报错原因MysqL使用源码安装后,数据库中存在匿名用户,可以通过任意用户名不输入密码即可登录数据库

MysqL> select host,user,password  from MysqL.user where (user) not in ('root');
+-----------------------+------+-------------------------------------------+
| host                  | user | password                                  |
+-----------------------+------+-------------------------------------------+
| localhost             |      |                                           |
| localhost.localdomain |      |                                           |
| %                     | neo  | *CC4C777F1511C297751B78287D6E05345D227819 |
| %                     | test | *443EF031E558E317B19BAD70BDF4E25FA73A89A7 |
+-----------------------+------+-------------------------------------------+
4 rows in set (0.00 sec)

MysqL> select host,user,password  from MysqL.user where (user) not in ('root','neo','test');
+-----------------------+------+----------+
| host                  | user | password |
+-----------------------+------+----------+
| localhost             |      |          |
| localhost.localdomain |      |          |
+-----------------------+------+----------+
2 rows in set (0.00 sec)

解决方法删除匿名用户

MysqL> delete  from MysqL.user where (user) not in ('root','neo','test');
Query OK, 2 rows affected (0.00 sec)

MysqL> flush privileges;
Query OK, 0 rows affected (0.00 sec)

之后新创建的用户即可正常登录数据库

[root@localhost software]# ./bin/MysqL -uneo -p'MysqL#2015'
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 1
Server version: 5.5.48-log production environment

copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered Trademark of Oracle Corporation and/or its
affiliates. Other names may be Trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MysqL> show grants;
+-----------------------------------------------------------------+
| Grants for neo@%                                                |
+-----------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'neo'@'%' IDENTIFIED BY PASSWORD <secret> |
| GRANT SELECT, INSERT, DELETE, CREATE ON `fire`.* TO 'neo'@'%'   |
+-----------------------------------------------------------------+
2 rows in set (0.00 sec)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐