为什么我会收到“用户‘root’@‘myhostname’的访问被拒绝”在 PHP 中连接到我的数据库时?

发布于 2024-09-02 07:19:35 字数 186 浏览 2 评论 0原文

我已经在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陌伤浅笑 2024-09-09 07:19:35

通常,对于 Web 应用程序,您不应以 root 身份连接到数据库。但是,您将帖子标记为 [phpmyadmin] 所以我假设您的问题出在 phpMyAdmin,在这种情况下您可能会以 root 身份连接。

如果是这种情况,我发现您在错误消息中提到了 myhostname。您是否尝试过连接到 localhost ?有时 MySQL root 用户无法从远程主机连接。

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 to localhost instead? Sometimes the MySQL root user cannot connect from remote hosts.

又怨 2024-09-09 07:19:35

您需要设置一些配置变量才能使 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

不再见 2024-09-09 07:19:35
GRANT ALL PRIVILEGES ON *.* TO monty@localhost
       IDENTIFIED BY 'indian' WITH GRANT OPTION;

替换您的用户名和密码,并通过选择您的数据库在 phpmyadmin 中执行它。

GRANT ALL PRIVILEGES ON *.* TO monty@localhost
       IDENTIFIED BY 'indian' WITH GRANT OPTION;

Replace your username and password and execute it in your phpmyadmin by selecting your database.

不喜欢何必死缠烂打 2024-09-09 07:19:35

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文