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

我连接到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 -u mike -p mypass

空格显然是允许在-u #uname#之间,但不允许在-p和#password#之间

因此需要:

mysql -u mike -pmypass

否则,在空格之间-p mpass mysql以' mpass '作为数据库名

其他回答

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.

只是想让你知道一个不寻常的情况下,我收到了同样的错误。也许这在将来会对某些人有所帮助。

我开发了一些基本视图,在开发站点创建,并将它们转移到生产站点。那周晚些时候,我修改了一个PHP脚本,突然出现了一个错误,用户“local-web-user”@“localhost”的访问被拒绝。数据源对象没有改变,所以我把注意力集中在MySQL中的数据库用户上,同时担心有人入侵我的网站。幸运的是,遗址的其他部分似乎没有受到损害。

后来证明,这些观点才是罪魁祸首。我们的对象传输是使用本地网站用户以外的另一个用户(并且是远程:admin@ip-address)完成的。因此,视图是用'admin'@'ip-address'作为定义符创建的。视图创建SECURITY default为

SQL SECURITY DEFINER

当local-web-user试图使用视图时,它会偶然发现定义者缺乏使用表的特权。一旦安全性更改为:

SQL SECURITY INVOKER

问题解决了。实际问题与基于错误消息的预期完全不同。

更新:在v8.0.15(可能是这个版本),PASSWORD()函数不起作用。

你必须:

确保你已经停止MySQL。 使用特权绕过安全模式运行服务器:sudo mysqld_safe——skip-grant-tables 登录:mysql -u root 更新mysql。SET authentication_string=null WHERE user ='root'; mysql> FLUSH PRIVILEGES; mysql >退出; 再次登录:mysql -u root mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd'

对我来说,在进入mysql时没有指定-p参数。

mysql -p

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

这太迟了

我尝试了所有这些其他答案,并运行了许多不同版本的mysql -u root -p,但从来没有运行过


Mysql -u root -p

然后按[ENTER]输入密码。


一旦我这么做了,就成功了。希望这能帮助到一些人。