MySQL 身份验证错误的原因:“Access Denied for user ‘xxx’@‘yyy’”?
当尝试使用 PHP-mysqli 访问数据库并且使用命令行 mysql 工作正常时,MySQL 给出错误 “Access returned for user 'xxx'@'yyy'”
可能存在哪些可能的原因具有完全相同的用户名、密码、套接字、数据库和主机的工具?
更新:mysql.user
表中确实有 3 个用户,每个用户都有不同的主机(但具有相同的哈希密码),其中一个设置为 localhost,一个设置为 127.0.0.1,一个设置为机器的主机名。 删除其中两个并将第三个的主机更改为“%”只会产生一种效果:现在使用命令行工具也拒绝访问。 做了一个,它产生了与 php 中拒绝的相同的 xxx@yyy 。
select user();
我之前在命令行中
What possible reasons could exist for MySQL giving the error “Access denied for user 'xxx'@'yyy'”
when trying to access a database using PHP-mysqli and working fine when using the command-line mysql tool with exactly the same username, password, socket, database and host?
Update:
There were indeed three users in the mysql.user
table, each one with a different host (but with the same hashed password), one was set to localhost, one to 127.0.0.1 and one to the machine’s host name. Deleting two of them and changing the host of the third to “%” had only one effect: now the access is denied using the command-line tool also.
I did do a
select user();
before that in the command line and it yielded the same xxx@yyy that were denied in php.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有时在 php/mysql 中,localhost 和 127.0.0.1 之间存在差异。
在 mysql 中,您根据主机名授予访问权限,对于本地用户,这将是 localhost。
我已经看到 php 尝试连接“myservername”而不是 localhost,尽管在配置中定义了“localhost”。
尝试在 mysql 中授予 127.0.0.1 的访问权限,并通过 127.0.0.1 端口 3306 在 php 中连接。
Sometimes in php/mysql there is a difference between localhost and 127.0.0.1
In mysql you grant access based on the host name, for localusers this would be localhost.
I have seen php trying to connect with 'myservername' instead of localhost allthough in the config 'localhost' was defined.
Try to grant access in mysql for 127.0.0.1 and connect in php over 127.0.0.1 port 3306.
如果有人仍然感兴趣:我从未解决过这个特定问题。 看来问题确实出在我运行 MySQL 的硬件上。 从那以后我再也没有见过类似的东西。
In case anyone’s still interested: I never did solve this particular problem. It really seems like the problem was with the hardware I was running MySQL on. I’ve never seen anything remotely like it since.
在我阅读您的更新后,我怀疑密码有错误。
您是否在密码中使用了“奇怪”的字符(可能会导致 utf-8/iso 编码问题)?
在主机字段中使用 % 将允许用户从任何主机进行连接。 所以唯一可能出错的是密码。
您可以创建另一个用户吗? 是否使用“授予所有由 'somesimplepw' 标识的 '...'@'%' 语法”,并尝试与该用户连接?
不要忘记“刷新权限”
有关如何创建新用户的信息,请点击 这里
After I read your update I would suspect an error in/with the password.
Are you using "strange" characters in your PW (something likely to cause utf-8/iso encoding problems)?
Using % in the Host field would allow the user to connect from any host. So the only thing that could be wrong would be the password.
Can you create another user. whith the "grant all on all for '...'@'%' identiefied by 'somesimplepw'" syntax, and try to connect with that user?
Don't forget to 'flush privelidges'
For info on how to create a new user klick here
今天,我的网络托管提供商的 FTP 服务遇到了一些问题,因此我决定实现一个本地虚拟网络服务器来在我的网站上运行。 我已经使用 phpMyAdmin 安装了 EasyPHP 14.1,并使用表创建了我的用户和数据库。
第一次尝试:失败。 我意识到我要找的桌子不存在。 -> 我解决了创建丢失的表的问题。
第二次尝试:失败。 我意识到我为新用户设置的用户名与我用于连接的用户名不同。 -> 我编辑了用户名。
第三次尝试:失败。 我意识到新的数据库名称与我在站点中用于连接的数据库名称不同。 -> 我编辑了数据库名称。
第四次尝试:失败。 我意识到我的新用户的权限之间没有“授予”。 我什至不知道“Grant”是什么意思,但让我们尝试启用它 -> 添加了“授予”权限。
第五次尝试:我赢了!
我希望我的小冒险可以帮助别人。 =)
Today the FTP service of my web hosting provider is having some trouble, so I decide to realize a local virtual webserver for working on my website. I have installed EasyPHP 14.1 with phpMyAdmin and I have created my user and my database with tables.
First attempt: failed. I realized that the table I was looking for didn't exist. -> I solved creating the missing table.
Second attempt: failed. I realized that username that I set for my new user was diffrent from the username I used for my connection. -> I edited username.
Third attempt: failed. I realized that new database name was diffrent from database name I use for connection in my site. -> I edited db name.
Forth attempt: failed. I realized that between privileges of my new user there wasn't "Grant". I don't even know what "Grant" means, but let's try to enable it -> Added "Grant" privilege.
Fifth attempt: I win!
I hope my little adventure could help someone. =)