gpt4 book ai didi

MySQL 错误 1045 (28000) : Access denied for user 'bill' @'localhost' (using password: YES)

转载 作者:行者123 更新时间:2023-11-29 15:58:04 25 4
gpt4 key购买 nike

首先让我提一下,我已经浏览了许多建议的问题,但没有找到相关的答案。这就是我正在做的事情。

我已连接到我的 Amazon EC2 实例。我可以使用以下命令使用 MySQL root 登录:

mysql -u root -p

然后我使用主机 % 创建了一个新的用户账单

CREATE USER 'bill'@'%' IDENTIFIED BY 'passpass';

授予用户 bill 所有权限:

grant all privileges on *.* to 'bill'@'%' with grant option;

然后我退出 root 用户并尝试使用 bill 登录:

mysql -u bill -p

输入了正确的密码并收到此错误:

ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)

最佳答案

您可能有一个匿名用户''@'localhost'''@'127.0.0.1'

根据the manual :

When multiple matches are possible, the server must determine which ofthem to use. It resolves this issue as follows: (...)

  • When a client attempts to connect, the server looks through the rows [of table mysql.user] in sorted order.
  • The server uses the first row that matches the client host name and user name.

(...)The server uses sorting rules that order rows with the most-specific Host values first.Literal host names [such as 'localhost'] and IP addresses are the most specific.

因此,当从 localhost 连接时,这样的匿名用户会“屏蔽”任何其他用户,例如 '[any_username]'@'%'

'bill'@'localhost' 确实匹配 'bill'@'%',但会匹配(例如)''@'localhost' 事先。

推荐的解决方案是删除该匿名用户(无论如何,这通常是一件好事)。

<小时/>

以下编辑大多与主要问题无关。这些只是为了回答本主题中其他评论中提出的一些问题。

编辑 1

通过套接字验证为 'bill'@'%'

    root@myhost:/home/mysql-5.5.16-linux2.6-x86_64# ./mysql -ubill -ppass --socket=/tmp/mysql-5.5.sock    Welcome to the MySQL monitor (...)        mysql> SELECT user, host FROM mysql.user;    +------+-----------+    | user | host      |    +------+-----------+    | bill | %         |    | root | 127.0.0.1 |    | root | ::1       |    | root | localhost |    +------+-----------+    4 rows in set (0.00 sec)        mysql> SELECT USER(), CURRENT_USER();    +----------------+----------------+    | USER()         | CURRENT_USER() |    +----------------+----------------+    | bill@localhost | bill@%         |    +----------------+----------------+    1 row in set (0.02 sec)        mysql> SHOW VARIABLES LIKE 'skip_networking';    +-----------------+-------+    | Variable_name   | Value |    +-----------------+-------+    | skip_networking | ON    |    +-----------------+-------+    1 row in set (0.00 sec)    

编辑2

完全相同的设置,只是我重新激活了网络,并且现在创建了一个匿名用户''@'localhost'

    root@myhost:/home/mysql-5.5.16-linux2.6-x86_64# ./mysql    Welcome to the MySQL monitor (...)        mysql> CREATE USER ''@'localhost' IDENTIFIED BY 'anotherpass';    Query OK, 0 rows affected (0.00 sec)        mysql> Bye    root@myhost:/home/mysql-5.5.16-linux2.6-x86_64# ./mysql -ubill -ppass \        --socket=/tmp/mysql-5.5.sock    ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)    root@myhost:/home/mysql-5.5.16-linux2.6-x86_64# ./mysql -ubill -ppass \        -h127.0.0.1 --protocol=TCP    ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)    root@myhost:/home/mysql-5.5.16-linux2.6-x86_64# ./mysql -ubill -ppass \        -hlocalhost --protocol=TCP    ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)

编辑3

与编辑 2 中的情况相同,现在提供匿名用户的密码。

    root@myhost:/home/mysql-5.5.16-linux2.6-x86_64# ./mysql -ubill -panotherpass -hlocalhost    Welcome to the MySQL monitor (...)    mysql> SELECT USER(), CURRENT_USER();    +----------------+----------------+    | USER()         | CURRENT_USER() |    +----------------+----------------+    | bill@localhost | @localhost     |    +----------------+----------------+    1 row in set (0.01 sec)

结论 1,来自编辑 1:可以通过套接字以 'bill'@'%' 身份进行身份验证。

编辑 2 中的结论 2:无论是通过 TCP 还是通过套接字连接,对身份验证过程都没有影响(除非一个人无法像其他人一样通过 'something'@'localhost' 进行连接)显然是一个套接字)。

结论 3,来自编辑 3:虽然我指定了 -ubil,但我已被授予匿名用户访问权限。这是因为上面建议的“排序规则”。请注意,在大多数默认安装中,a no-password, anonymous user exists (并且应该固定/删除)。

关于MySQL 错误 1045 (28000) : Access denied for user 'bill' @'localhost' (using password: YES),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56352934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com