为什么我收到“用户访问被拒绝”的消息? PHP 中的错误?

发布于 2024-09-11 12:50:32 字数 543 浏览 2 评论 0原文

我正在运行此代码:

include '../includes/connection.php';
$conn = dbConnect('backup');

$tableName  = 'orders';
$backupFile = '../backup/db-backup(' . $date . ').sql';
$query      = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = $conn->query($query) or die(mysqli_error($conn));

我收到此错误:

用户访问被拒绝 'ideapale_amadmin'@'localhost'(使用 密码:是)

我知道密码和用户名是正确的,并且我已经测试了在不运行查询的情况下连接到数据库并且工作正常。另外,我当前使用的用户拥有所有权限。因此,我认为我的sql语句有问题。

为什么我收到“用户访问被拒绝”错误?

I am running this code:

include '../includes/connection.php';
$conn = dbConnect('backup');

$tableName  = 'orders';
$backupFile = '../backup/db-backup(' . $date . ').sql';
$query      = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = $conn->query($query) or die(mysqli_error($conn));

I am getting this error:

Access denied for user
'ideapale_amadmin'@'localhost' (using
password: YES)

I know the password and username is correct, and I have tested connecting to the database without running the query and that works fine. Also, the user I am currently using has all privileges. Therefore, I think there is something wrong with my sql statement.

Why am I getting the 'access denied for user' error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

欢烬 2024-09-18 12:50:32

很抱歉这么说,但显然密码正确。要么是你的权限不正确。

Sorry to say it, but obviously the password is not correct. Either that or you've got incorrect privileges.

橘寄 2024-09-18 12:50:32

已经在我的评论中说过了,但我认为这是解决方案:

“FILE”权限设置为全局,也不是​​针对特定数据库设置的 - 我认为您忽略了这一点,因此用户没有 权限... INTO OUTFILE (并且,也不适用于LOAD DATA INFILE...

编辑:授予此权限的查询(出于我的想法,未经测试):

GRANT FILE ON *.* TO 'myuser'@'localhost' IDENTIFIED BY 'mypasswd';

EDIT2: 要在 phpMyAdmin 中进行设置,只需单击 Server: localhost (这应该是您打开 phpMyAdmin 时的起始页),然后单击 Privileges,选择您的用户并在数据部分添加勾选或FILE(因此,只需不要向下滚动并选择特定数据库)

编辑3:如果您使用方法1,请确保您以root身份运行授予语句 - 用户无法为自己授予权限(如果可以,所有这些权限内容将毫无意义)

already said this in my comment, but i think this is the solution:

"FILE"-permissions are set global, nor for a specific database - i think you have overlooked that, so the user has no permissions for ... INTO OUTFILE (and, also, not for LOAD DATA INFILE...)

EDIT: the query to grant this privileges (out of my head, not tested):

GRANT FILE ON *.* TO 'myuser'@'localhost' IDENTIFIED BY 'mypasswd';

EDIT2: to set this in phpMyAdmin, just click on Server: localhost (which should be the start-page when you open phpMyAdmin) then click on Privileges, select your user and add the tick or FILE in the Data-section (so, simply don't scroll down and select a specific database)

EDIT3: if you use method 1, make sure you run the grant-statement as root - a user can't grant privileges for himself (if he could, all this permission-stuff would be senseless)

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