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

我连接到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时没有指定-p参数。

mysql -p

我没有问题,但它是错误的调用mysql没有密码。

其他回答

I discovered yet another case that appears on the surface to be an edge case; I can export to the file system, via SELECT INTO .. OUTFILE as root, but not as regular user. While this may be a matter of permissions, I've looked at that, and see nothing especially obvious. All I can say is that executing the query as a regular user who has all permissions on the data base in question returns the access denied error that led me to this topic. When I found the transcript of a successful use of SELECT INTO … OUTFILE in an old project, I noticed that I was logged in as root. Sure enough, when I logged in as root, the query ran as expected.

所以对我来说,这个问题与我映射的端口有关。

3306 => 3306不工作(因为我有一个本地mysql运行)

3307 => 3306工作!

这是在建立ssh隧道的上下文中:

ssh -N -L 3307:rdsDns:3306 ec2User@ec2Dns -i key.pem -v

3307为本端端口,3306为远端端口。

在Windows上,解决方法如下:

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

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

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 UI(如SQLYoug),生成的密码带有错误的散列,也会出现这个问题。

用SQL脚本创建用户可以解决这个问题。