Jump to content

Grant File privalage then remove it to a user


EchoFool
Go to solution Solved by kicken,

Recommended Posts

Hey

 

I have a query that looks like this:

     

GRANT FILE ON [dbName].* TO '[user]'@'127.0.0.1' IDENTIFIED BY '[password]'  WITH GRANT OPTION

 

 

 

But i get this error: 

 

SQLSTATE[28000]: Invalid authorization specification: 1045 Access denied for user '[hidden]'@'localhost' (using password: YES)

 

 

 

Why is this happening? In Cpanel the user has all privalages yet FILE is not one of them and i cannot seem to grant it either =/ Here is my code:


 

$dsn = 'mysql:dbname=hidden;host=127.0.0.1';
$user = //hidden
$password = //hidden

	try {
		$pdo = new PDO($dsn, $user, $password);
		
	} catch (PDOException $e) {
		echo 'Connection failed: ' . $e->getMessage();
		exit;
	}

	$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

//grant file permission temporarily		
        $stmt = $pdo->prepare("GRANT FILE ON [hidden].* TO '[hidden]'@'127.0.0.1' IDENTIFIED BY '[hidden]'  WITH GRANT OPTION");
			try {
				$stmt->execute(array(1));
			} catch (PDOException $e) {
				echo $e -> getMessage(); exit; //ERROR IS HERE
			}		

Where am i going wrong here?

 

p.s i have used [hidden] solely for this post, the script does have the real login credentials :)

Edited by EchoFool
Link to comment
Share on other sites

  • Solution

You can't have a user that doesn't have a particular privilege grant itself that missing privilege. You need to use a user which has that ability and the ability to grant privileges in order to grant it. Typically this means you have to use the root user.

 

I'm not that familiar with cpanel but if you can't grant it through there, and don't have direct access to the mysql root user then your host probably doesn't allow that privilege.

 

If you are infact trying to grant a privilege across users rather than the same user (as your code reads), then make sure the source user has all the necessary privileges and the ability to grant.

Edited by kicken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.