MySQL无法使用我创建的用户

时间:2022-02-12 15:06:15

In MySQL I create two users:

在MySQL中我创建了两个用户:

CREATE USER 'Bob'@'localhost' IDENTIFIED by 'p'
CREATE USER 'Alice'@'%' IDENTIFIED by 'a'

And then, when I try to connect with: "mysql -u Alice -p" it fails, telling me

然后,当我尝试连接时:“mysql -u Alice -p”它失败了,告诉我

Error 1045 (28000) Access denied for user 'Alice'@'localhost'

T The same with Bob.

与鲍勃一样。

Anyone knows why occur this?

谁知道为什么会这样?

EDIT:

MySQL asks for the password, and the I putand give me that error.

MySQL要求输入密码,而我putand给我的错误。

EDIT 2: I am connecting in remote, not in local, so the only that must work is Alice.

编辑2:我在远程连接,而不是在本地连接,所以唯一必须工作的是Alice。

3 个解决方案

#1


0  

Log in as root and do this:

以root身份登录并执行以下操作:

GRANT ALL privileges ON *.* TO Bob@localhost IDENTIFIED BY 'p' WITH GRANT OPTION;

#2


0  

According to a comment in Using % for host when creating a MySQL user,

根据创建MySQL用户时使用%for host的注释,

Actually there is, 'localhost' is special in mysql, it means a connection over a unix socket (or named pipes on windows I believe) as opposed to a TCP/IP socket. using % as the host does not include 'localhost' – nos May 30 '12 at 20:45

实际上,'localhost'在mysql中是特殊的,它意味着通过unix套接字(或我认为的Windows上的命名管道)的连接,而不是TCP / IP套接字。使用%作为主机不包括'localhost' - nos 5月30日'12在20:45

As a result, if your mysql -u alice... command connects using a Unix socket rather than at 127.0.0.1, you'll need to

因此,如果您的mysql -u alice ...命令使用Unix套接字而不是127.0.0.1连接,则需要

CREATE USER 'Alice'@'localhost' IDENTIFIED by 'a'

#3


0  

did you tried flushing privileges with that command ?

你试过用那个命令刷新特权吗?

FLUSH PRIVILEGES;

#1


0  

Log in as root and do this:

以root身份登录并执行以下操作:

GRANT ALL privileges ON *.* TO Bob@localhost IDENTIFIED BY 'p' WITH GRANT OPTION;

#2


0  

According to a comment in Using % for host when creating a MySQL user,

根据创建MySQL用户时使用%for host的注释,

Actually there is, 'localhost' is special in mysql, it means a connection over a unix socket (or named pipes on windows I believe) as opposed to a TCP/IP socket. using % as the host does not include 'localhost' – nos May 30 '12 at 20:45

实际上,'localhost'在mysql中是特殊的,它意味着通过unix套接字(或我认为的Windows上的命名管道)的连接,而不是TCP / IP套接字。使用%作为主机不包括'localhost' - nos 5月30日'12在20:45

As a result, if your mysql -u alice... command connects using a Unix socket rather than at 127.0.0.1, you'll need to

因此,如果您的mysql -u alice ...命令使用Unix套接字而不是127.0.0.1连接,则需要

CREATE USER 'Alice'@'localhost' IDENTIFIED by 'a'

#3


0  

did you tried flushing privileges with that command ?

你试过用那个命令刷新特权吗?

FLUSH PRIVILEGES;