Link to home
Start Free TrialLog in
Avatar of aberns
abernsFlag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of cr4ck3rj4ck
cr4ck3rj4ck
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aberns

ASKER

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....
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.
Avatar of aberns

ASKER

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

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 :)