为什么我收到“用户访问被拒绝”的消息? PHP 中的错误?
我正在运行此代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很抱歉这么说,但显然密码不正确。要么是你的权限不正确。
Sorry to say it, but obviously the password is not correct. Either that or you've got incorrect privileges.
已经在我的评论中说过了,但我认为这是解决方案:
“FILE”权限设置为全局,也不是针对特定数据库设置的 - 我认为您忽略了这一点,因此用户没有
权限... INTO OUTFILE
(并且,也不适用于LOAD DATA INFILE...
)编辑:授予此权限的查询(出于我的想法,未经测试):
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 forLOAD DATA INFILE...
)EDIT: the query to grant this privileges (out of my head, not tested):
EDIT2: to set this in phpMyAdmin, just click on
Server: localhost
(which should be the start-page when you open phpMyAdmin) then click onPrivileges
, select your user and add the tick orFILE
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)