mysql 用户访问被拒绝 [英] Access denied for mysql user

查看:92
本文介绍了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.

这篇关于mysql 用户访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆