mysql 用户访问被拒绝
当我尝试通过密码标识的用户 'spot'@'localhost'
访问我的数据库时,出现此错误.
I get this error when I try to access my database via the user 'spot'@'localhost'
identified by its password.
PermissionsError: (1045, "Access denied for user 'spot'@'localhost' (using password: YES)", None)
我使用这两行创建了这个用户:
I create this user using these two lines:
create user 'spot'@'localhost' identified by 'fakepasswd';
grant all privileges on *.* to 'spot'@'localhost';
当我在本地运行此代码时,它运行良好.当我在另一台机器上运行此代码时,出现上述错误.然而,当我在两台机器上运行 show grants for 'spot'@'localhost'
时,它们都给我相同的输出:
When I run this code locally, it works fine. When I run this code on a different machine, I get the aforementioned error.
Yet when I run show grants for 'spot'@'localhost'
on both machines, they both give me the same output:
GRANT ALL PRIVILEGES ON *.* TO 'spot'@'localhost' IDENTIFIED BY PASSWORD '*196BDEDE2AE4FRO4CA44C47D54D78478C7E2BD7B7'
如何调试这个访问问题?
How can I debug this access problem?
您不仅需要从 localhost 授予权限,还需要运行以下查询:
Yo need to grant privileges not only from localhost, run this querys:
create user 'spot'@'%' identified by 'fakepasswd';
grant all privileges on *.* to 'spot'@'%';
flush privileges;
这允许用户从任何 ip 连接,您可以将 %
替换为您服务器的 ip.
This allow the user to connect from ANY ip, you can replace the %
with the ip of your server.