tags:

views:

45

answers:

2

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?

+3  A: 

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

Daniel Egeberg
I already set all privileges. What other privileges do I need?
zeckdude
+2  A: 

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)

oezi
How would I set global permissions on a server? I could probably figure out how to do that in phpmyadmin on wamp, but I only know how to set Privileges for a user connected to a database. Where do I set the global privileges for a user?
zeckdude
@zeckdude: please see my edit
oezi
I get the access denied error when I try to run the sql statement you gave me.
zeckdude
@zeckdude: please see my other edit ;)
oezi
So if I use method 1, it should be GRANT FILE ON *.* TO 'root'@'localhost' IDENTIFIED BY 'mypasswd'?
zeckdude
no, you should _log in to mysql as root_ and then `GRANT FILE ON *.* TO 'theuseriwanttogiveprivileges'@'localhost' IDENTIFIED BY 'theuserspasswd'`
oezi