• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 781
  • Last Modified:

Setting up a backup routine with Select Into OUTFILE or alternative?

Hello,

I am trying to create a php backup routine for my MySQL databases that I can run as CRON jobs a few times a day.
Here is what I have so far:

The error I get is:

Access denied for user 'database'@'%' (using password: YES)

I have set the directorypath folder permissions to 777 and created the file name in advance.

Can you provide assistance with this method or suggest an alternate script? Thank you very much.

connect stuff...
$tableName  = 'SampleTable';
$backupFile = $_SERVER['DOCUMENT_ROOT'].'/directorypath/Sampletable.sql';
$query      = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = mysql_query($query) or die(mysql_error());
mysql_close($link);

Open in new window

0
aberns
Asked:
aberns
  • 3
  • 2
1 Solution
 
cr4ck3rj4ckCommented:
Hi there,

INTO OUTFILE is a MySQL file query and therefore it is not limited by the OS permissions (CHMOD). I would say that your user hasn't got the proper GRANT privileges to enable you to perform this operation.

If you're on shared hosting, I doubt you're going to be able to get the permissions from the provider.

If it's your server then you may want to look at the following:
http://www.webhostingtalk.com/archive/index.php/t-375379.html

GRANT FILE is the command you're looking for to give file permissions.

Hope that helps,
CJ
0
 
abernsAuthor Commented:
Okay, thanks. It is a shared server so you're right...I will not be able to get this permission. I am looking at another solution....
0
 
cr4ck3rj4ckCommented:
You may want to check this out:
http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html

It's a MySQL tool to run backups and it can be scheduled as a cron job.
0
 
abernsAuthor Commented:
For the link you sent, it looks like I need shell access? The only access I have is via PHPMyAdmin or by writing a PHP script.

I was actually looking into this solution:http://www.sematopia.com/?p=61

0
 
cr4ck3rj4ckCommented:
That is basically a PHP shell using exec() to use the mysqldump command.

If you have permission to exec() it looks like a reasonable solution. Give it a go :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now