简体   繁体   English

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

[英]Why am I getting 'access denied for user' error in php?

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) 用户'ideapale_amadmin'@'localhost'的访问被拒绝(使用密码:是)

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. 因此,我认为我的sql语句出了点问题。

Why am I getting the 'access denied for user' error? 为什么会出现“拒绝用户访问”错误?

Sorry to say it, but obviously the password is not correct. 不好意思,但是密码显然正确。 Either that or you've got incorrect privileges. 要么,要么您拥有不正确的特权。

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... ) “ FILE”权限设置为全局设置,也不是针对特定数据库设置的-我认为您已经忽略了这一点,因此用户没有权限... INTO OUTFILE (并且也没有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) EDIT2:要在phpMyAdmin中进行设置,只需单击Server: localhost (当您打开phpMyAdmin时应为起始页),然后单击Privileges ,选择您的用户并在Data部分中添加对号或FILE (因此,只需不要向下滚动并选择特定的数据库)

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) EDIT3:如果使用方法1,请确保以root用户身份运行grant-statement-用户无法为其授予特权(如果可以的话,所有这些权限将毫无意义)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM