MySQL 错误 1045,“用户 'user'@'localhost' 的访问被拒绝(使用密码:YES)”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15989030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL Error 1045, "Access denied for user 'user'@'localhost' (using password: YES)"
提问by Carlos Eugenio Thompson Pinzón
This question seem to be asked a lot however I cannot find a definitive answer.
这个问题似乎被问了很多,但我找不到明确的答案。
I am making some webapp tests using MySQL, and at the beginning I used the 'root'user (with a non-empty password). My root user is working fine from the apps (tested from PHP and Python's Django), from the command line, and with PHPMyAdmin.
我正在使用 MySQL 进行一些 webapp 测试,一开始我使用了“root”用户(使用非空密码)。我的 root 用户在应用程序(通过 PHP 和 Python 的 Django 测试)、命令行和 PHPMyAdmin 中工作正常。
However I don't wanted to use the the root user, so I created another user, and I granted all privileges to the databases that user should need. (I used PHPMyAdmin logged as 'root'for this task).
但是,我不想使用 root 用户,所以我创建了另一个用户,并将所有权限授予该用户应该需要的数据库。(我使用 PHPMyAdmin 以“root”身份登录此任务)。
The new user cannot log in to MySQL. Neither from the Django app, nor PHPMyAdmin, nor the command line.
新用户无法登录 MySQL。既不是来自 Django 应用程序,也不是来自 PHPMyAdmin,也不是来自命令行。
I have two possible suspicions:
我有两个可能的怀疑:
there is a global privilege the user lacks. (As I said, I granted all database privileges, however I have not granted any global privileges);
the user's configured host. ('root'has four lines in the mysql.usertable, for hosts 'localhost', 'my-pc-name', '127.0.0.1'and '::1'; while the new user has one line for host '%')
用户缺乏全局权限。(正如我所说,我授予了所有数据库权限,但我没有授予任何全局权限);
用户配置的主机。('root'在mysql.user表中有四行,对于主机'localhost'、'my-pc-name'、'127.0.0.1'和'::1';而新用户有一行用于主机' %')
(I have double-checked the password, so I am confident this is not a password problem.)
(我已经仔细检查了密码,所以我确信这不是密码问题。)
采纳答案by johnnaras
% means that the new user can access the database from any host.
% 表示新用户可以从任何主机访问数据库。
However, if you supplied the CREATE USER statement would be much more useful.
但是,如果您提供 CREATE USER 语句会更有用。
In addition, check MySQL Manual below, where it explains why a user should have both @'localhost'
and @'%'
:
此外,请查看下面的 MySQL 手册,其中解释了为什么用户应该同时拥有@'localhost'
和@'%'
:
回答by yasin
restarting mysql server + "flush privileges;" command solved it for me
重启mysql服务器+“刷新权限”;命令为我解决了它