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

我连接到Amazon EC2实例。我可以用这个命令登录MySQL根目录:

mysql -u root -p

然后我用host %创建了一个新的用户帐单

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

授予用户bill的所有权限:

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

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

mysql -u bill -p

输入正确的密码并得到以下错误:

错误1045(28000):用户“账单”@“localhost”(使用密码:YES)的访问被拒绝


当前回答

MySQL account names consist of a user name and a host name, The name 'localhost' in host name indicates the local host also You can use the wildcard characters “%” and “_” in host name or IP address values. These have the same meaning as for pattern-matching operations performed with the LIKE operator. For example, a host value of '%' matches any host name, whereas a value of '%.mysql.com' matches any host in the mysql.com domain. '192.168.1.%' matches any host in the 192.168.1 class C network.

以上只是介绍:

实际上,用户“bill”@“localhost”和“bill”@“%”是不同的MySQL帐户,因此两者都应该使用自己的身份验证细节,如密码。

欲了解更多信息,请参阅http://dev.mysql.com/doc/refman//5.5/en/account-names.html

其他回答

当你输入mysql -u root -p时,你是在通过本地unix套接字连接到mysql服务器。

不管你给的授权是什么,'bill'@'%'只匹配TCP/IP连接。

如果你想要授予对本地unix套接字的访问权限,你需要授予'bill'@'localhost'权限,奇怪的是,这与'bill'@'127.0.0.1'不一样。

您也可以使用TCP/IP连接mysql命令行客户端,以匹配您已经授予的权限,例如运行mysql -u root -p -h 192.168.1.123或任何您的本地IP地址。

当你的密码包含一些特殊字符,如@,$等,也会发生这种情况。 为了避免这种情况,你可以把password用单引号括起来:

$ mysql -usomeuser -p's0mep@$$w0Rd'

或者在输入时不用密码。请留空,然后在终端要求时输入。这是推荐的方法。

$ mysql -usomeuser -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 191
Server version: 5.5.46-0ubuntu0.14.04.2 (Ubuntu)

Copyright (c) 2000, 2015, 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>

不确定其他人是否会发现这有帮助,但我遇到了同样的错误,并搜索任何匿名用户…但实际上并没有。问题最终是用户帐户被设置为“要求SSL”-这是我在PHPMyAdmin通过进入用户帐户并单击编辑用户的权限发现的。只要我取消了这个选项,一切都按预期工作!

我为自己找到的最好的解决办法是。

我的用户是声纳,每当我试图从外部或其他机器连接到我的数据库,我得到错误

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

此外,我正在尝试从另一台机器和通过詹金斯工作我的URL访问是

alm-lt-test.xyz.com

如果你想远程连接,你可以用以下不同的方式指定它:

mysql -u sonar -p -halm-lt-test.xyz.com
mysql -u sonar -p -h101.33.65.94
mysql -u sonar -p -h127.0.0.1 --protocol=TCP
mysql -u sonar -p -h172.27.59.54 --protocol=TCP

要访问这个URL,你只需要执行以下查询。

GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'alm-lt-test.xyz.com' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'127.0.0.1' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'172.27.59.54' IDENTIFIED BY 'sonar';

在Windows上,解决方法如下:

错误1045(28000):拒绝访问用户'root'@'localhost'(使用密码:NO)

从控制面板卸载mysql 删除C:\Program Files,C:\Program Files (x86)和C:\ProgramData目录下的MySql文件夹 安装mysql