MySQL 错误 1045 (28000):用户访问被拒绝(使用密码:是)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40680621/
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 (using password: YES)
提问by Licia
I am trying to have a simple mysql Database on a server and another database on another server that connects to it.
我正在尝试在服务器上建立一个简单的 mysql 数据库,并在另一台连接到它的服务器上建立另一个数据库。
I have done the following :
我做了以下工作:
- Installed mysql-server
- Created the database
Created the user with :
CREATE USER admin@'localhost' IDENTIFIED BY 'admin';
Given the privileges to this user with :
GRANT ALL PRIVILEGES ON confWeb.* TO admin@'';
Opened the bind-adress
- 安装mysql服务器
- 创建了数据库
创建用户:
创建用户 admin@'localhost' 由 'admin' 标识;
授予此用户的权限:
将 confWeb.* 上的所有权限授予 admin@'';
打开绑定地址
Now when I launch the command mysql -u admin -p -h <address>
from another server, it just tells me again and again :
现在,当我mysql -u admin -p -h <address>
从另一台服务器启动命令时,它只是一次又一次地告诉我:
ERROR 1045 (28000): Access denied for user 'admin'@'X.X.X.X' (using password: YES)
I really have no idea what to do at this point. I think I've tried everything.
I tried putting GRANT OPTION
in the end of the GRANT line, I tried allowing a lot of different addresses but nothing worked.
我真的不知道此时该怎么办。我想我已经尝试了一切。我尝试GRANT OPTION
在 GRANT 行的末尾放置,我尝试允许许多不同的地址,但没有任何效果。
回答by spencer7593
In MySQL, a user is identified by both userand host.
在 MySQL 中,用户由user和host标识。
This user:
该用户:
admin@localhost
is notthe same user as
是不相同的用户
admin@'10.242.167.235'
As one option, you could do this to allow connection:
作为一种选择,您可以这样做以允许连接:
GRANT USAGE ON *.* TO admin@'10.242.167.235' IDENTIFIED BY 'mysecret' ;
GRANT ALL ON confWeb.* TO admin@'10.242.167.235' ;
For a longer discussion of the MySQL Access Privilege System, including "wildcards", the special meaning of localhost, using IP addresses instead of hostnames, etc.
有关 MySQL 访问权限系统的更长讨论,包括“通配符”、localhost 的特殊含义、使用 IP 地址而不是主机名等。
http://dev.mysql.com/doc/refman/5.7/en/privilege-system.html
http://dev.mysql.com/doc/refman/5.7/en/privilege-system.html
回答by Licia
I do not really know why, but appareantly, it worked when I used the with grant option
and first gave access to the database, and then to its tables.
Here is the list of commands that I entered :
我真的不知道为什么,但显然,当我使用with grant option
并首先访问数据库,然后访问它的表时,它起作用了。这是我输入的命令列表:
mysql> create user 'admin'@'localhost' identified by 'admin';
mysql> grant all privileges on confWeb to 'admin'@'10.69.101.%' identified by 'admin' with grant option;
mysql> grant all privileges on confWeb.* to 'admin'@'10.69.101.%' identified by 'admin' with grant option;
mysql> flush privileges;
Again, I don't really know why it didn't work before and the answers that I saw look like all the documentation I have seen but it looks my problem was somewhere else.
同样,我真的不知道为什么它以前不起作用,我看到的答案看起来像我看过的所有文档,但看起来我的问题出在其他地方。
回答by Anurag Singh
Use following step:-
使用以下步骤:-
CREATE USER 'user name'@'IP or % or localhost' IDENTIFIED BY 'password';
GRANT all privileges ON *.* TO 'user name'@'IP or % or localhost' IDENTIFIED BY 'password' ;
flush privileges;
Here in the place of "IP"; you use remote server ip where you want to connect the server.You can also use "%" for useage databases from any plcae in the world.
在这里代替“IP”;您在要连接服务器的地方使用远程服务器 ip。您还可以使用“%”表示来自世界上任何地方的使用数据库。
Now, in Grant option; In the place of "all privileges" you can given access seperately like as select,alter,update etc.
现在,在授予选项中;在“所有权限”的位置,您可以单独授予访问权限,例如选择、更改、更新等。