为什么我会收到“用户‘root’@‘myhostname’的访问被拒绝”在 PHP 中连接到我的数据库时?
我已经在mandriva linux 2010.1上设置了一个Apache服务器。但问题是每当我尝试连接数据库时,都会出现以下错误:
错误:数据库错误:SQLSTATE[28000] [1045] 用户访问被拒绝 'root'@'myhostname'(使用密码: 是的)
I have set up an Apache server on mandriva linux 2010.1. But the problem is whenever I'm trying to connect with the database, it's giving me the following error:
Error:Database error: SQLSTATE[28000]
[1045] Access denied for user
'root'@'myhostname' (using password:
YES)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通常,对于 Web 应用程序,您不应以
root
身份连接到数据库。但是,您将帖子标记为[phpmyadmin]
所以我假设您的问题出在 phpMyAdmin,在这种情况下您可能会以 root 身份连接。如果是这种情况,我发现您在错误消息中提到了
myhostname
。您是否尝试过连接到localhost
?有时 MySQLroot
用户无法从远程主机连接。Normally for a web application, you shouldn't connect to the database as
root
. However you tagged your post as[phpmyadmin]
so I assume your issue is with, well, phpMyAdmin, in which case you might be connecting as root.If this is the case, I see that you mentioned
myhostname
in your error message. Have you tried connecting tolocalhost
instead? Sometimes the MySQLroot
user cannot connect from remote hosts.您需要设置一些配置变量才能使 phpmyadmin 工作:
http://www.phpmyadmin.net/documentation/Documentation.html#config
you need to set some configuration variables for phpmyadmin to work:
http://www.phpmyadmin.net/documentation/Documentation.html#config
替换您的用户名和密码,并通过选择您的数据库在 phpmyadmin 中执行它。
Replace your username and password and execute it in your phpmyadmin by selecting your database.
看一下 "5.4.7. 拒绝访问的原因MySQL 在线文档中的错误” 和 使用身份验证模式在 PHPMyAdmin 文档中。
Take a look at "5.4.7. Causes of Access-Denied Errors" in the MySQL online documentation and Using authentication modes" in the PHPMyAdmin documentation.