MySQL ERROR 1045 (28000): 用户 'username'@'%' 访问被拒绝(使用密码:YES)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19220085/
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
ERROR 1045 (28000): Access denied for user 'username'@'%' (using password: YES)
提问by Django Anonymous
I Installed MySQL on my CentOS 6.4 server. I logged into my root and changed its password.
我在 CentOS 6.4 服务器上安装了 MySQL。我登录到我的 root 并更改了密码。
Later I thought that I should make a new user and use that user as my default user, So I created a new user name golden
using the following command:
后来我想我应该创建一个新用户并将该用户用作我的默认用户,所以我golden
使用以下命令创建了一个新用户名:
CREATE USER 'golden'@'%' IDENTIFIED BY 'password';
Then I applied permission to the user golden
:
然后我向用户申请了权限golden
:
GRANT ALL PRIVILEGES ON * . * TO 'golden'@'%';
FLUSH PRIVILEGES;
Now this user: golden
was able to do everything. So I finally Deleted the root user
. Now I am stuck up on granting privilege to my one another new user.
现在这个用户:golden
能够做任何事情。所以我终于Deleted the root user
。现在我坚持为我的另一个新用户授予特权。
I created another user, when I was logged in through golden
(At this time I had already deleted the root
user and command successfully created and the new user I am able to see it in list also)
我创建了另一个用户,当我通过登录时golden
(此时我已经删除了root
成功创建的用户和命令,新用户我也可以在列表中看到它)
CREATE USER 'fashion'@'%' IDENTIFIED BY 'password';
Then the following commands below gives me error:
然后下面的命令给了我错误:
GRANT ALL PRIVILEGES ON *.* TO 'fashion'@'%';
ERROR:ERROR 1045 (28000): Access denied for user 'golden'@'%' (using password: YES)
错误:错误 1045 (28000):用户 'golden'@'%' 访问被拒绝(使用密码:是)
I also tried the following command the result is below:
我还尝试了以下命令,结果如下:
mysql> SELECT USER(),CURRENT_USER(); +------------------+----------------+ | USER() | CURRENT_USER() | +------------------+----------------+ | golden@localhost | golden@% | +------------------+----------------+
If I wont be able to give access to this user then how can I login and use the database? Kindly help.
如果我无法授予此用户访问权限,那么我如何登录和使用数据库?请帮助。
EDIT 1: The following command gives me the following result
编辑 1:以下命令给了我以下结果
mysql> select user, host FROM mysql.user; +------------+-------+ | user | host | +------------+-------+ | golden | % | | fashion | % | +------------+-------+
回答by Alma Do
First of, I can't imagine the reason why you've deleted root
user. But back to the question - you should specify WITH GRANT OPTION
, like this:
首先,我无法想象您删除root
用户的原因。但是回到问题 - 您应该指定WITH GRANT OPTION
,如下所示:
(However this should be opted after you get the mysql re-installed as if you don't have the root
access and the user is not having the sufficient privileges also, then the best is to restart the install process and make the user and grant them privileges the way defined below)
(但是,在您重新安装 mysql 后应该选择此选项,就好像您没有root
访问权限并且用户也没有足够的权限,那么最好是重新启动安装过程并使用户并授予他们特权如下定义的方式)
mysql> create user 'golden'@'localhost' identified by 'password'; Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges on *.* to golden@localhost with grant option; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
and then
进而
mysql> select current_user(); +------------------+ | current_user() | +------------------+ | golden@localhost | +------------------+ 1 row in set (0.00 sec) mysql> create database testing; Query OK, 1 row affected (0.03 sec) mysql> grant all privileges on testing.* to test; Query OK, 0 rows affected (0.02 sec) mysql> drop database testing; Query OK, 0 rows affected (0.12 sec)
-but yet again, think twice before deleting root
user.
- 但再一次,在删除root
用户之前三思而后行。
回答by user2853770
have you tried this?
你试过这个吗?
update mysql.user set grant_priv='Y' where user='golden';
flush privileges;
and then quit and re-connect to the database as user golden.
然后退出并以gold 用户身份重新连接到数据库。
回答by ashish maheshwari
most easy way to solve this problem is--
解决这个问题最简单的方法是——
1.go to control pannel and make hidden files and folders visible (if not done before) 2.now go to your c drive and open a hidden folder "program data" in it. 3.search mysql folder and delete it. 4.uninstall mysql 5.1. 5. reinstall it using wizard. it will ask ur new password.. :) enjoy
1.转到控制面板并使隐藏的文件和文件夹可见(如果以前没有做过) 2.现在转到您的c驱动器并在其中打开一个隐藏的文件夹“程序数据”。3.搜索mysql文件夹并删除它。4.卸载mysql 5.1。5.使用向导重新安装它。它会询问你的新密码.. :) 享受