Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   Backing up a MySQL database to a .txt file using a PHP script (http://www.greenguysboard.com/board/showthread.php?t=37701)

Fonz 2007-01-23 08:48 AM

Backing up a MySQL database to a .txt file using a PHP script
 
I'm looking for some way to back up a huge MySQL database to a downloadable .txt file. I have found some PHP scripts like this one: http://www.zend.com/codex.php?id=634&single=1 but that doesn't seem to do anything.

Can anyone (cd34 or so :D ) can help me out here please?
Thanx!

cd34 2007-01-23 09:02 AM

if it is huge, you're likely to run into timeouts on apache that aren't going to allow it to be downloaded completely.

What you can try is something like forking a process that does

mysqldump -q -u username -ppassword databasename > /tmp/dump.sql

and writing the pid of the forked process so that you can check to see if the process is still running. With most apache servers, in 2-3 minutes a php script (or any cgi script) will time out and kill the process -- resulting in an incomplete dump.

Alternatively you can write your own dump that will go through the records one by one and output a . or space to the screen to keep apache from timing out.

Fonz 2007-01-23 09:20 AM

Thanx, I'll give that a try :)

Oh and does there has to be a space between -p password?

cd34 2007-01-23 09:52 AM

it needs to be -ppassword or -p'password' if there are characters that the shell might escape.

CPR 2007-01-29 06:13 PM

I would generally recommend using mysqlhotcopy, mainly because its faster than mysqldump, although it uses locks.
But since you need a PHP script to do the work you probably don't have access to the server?!

Check it out http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html


All times are GMT -4. The time now is 06:41 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc