Click to See Complete Forum and Search --> : PHP/MySQL Dump to File
mididelight
06-25-2006, 11:42 PM
Hello,
So I want to create a php script that will use the MySQL dump feature to dump my database (and specified tables) to a file that I will create on the fly with php. Is this possible? I did some research but could not find anything.
Any help is appreciated, thanks.
PS I know I can just use PHPMyAdmin to dump the contents of my database, but I am trying to create this script, so it will automatically make a file on the server and save the dump contents.
Thanks
timmah
06-26-2006, 05:32 PM
cron this
$filename= "backupname-$datestamp.sql.gz"; // The name path of the dump file
$command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename";
$result = passthru($command);
mididelight
06-26-2006, 06:42 PM
would doing it this way require me to have the file already created on the server? I wanted to create the file automatically.
Also in the MySQLDump command, how do I specify which tables to dump. I woulld like to ignore some tables.
timmah
06-26-2006, 06:55 PM
no you will not have to have the file already on the server. it will automatically create it in the directory.
http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html
You could then ftp that file or email it if it was small or whatever you want to do with it...
chazzy
06-26-2006, 07:06 PM
Here's the best source for mysqldump
http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html
mididelight
06-26-2006, 09:07 PM
so i try this:
$command = "mysqldump dbname orders > file.sql";
and i see that the file is created, but the file is empty. is there an error log I can look up?
Am I doing this wrong? I tried it with the commands for user and password but that didnt work either.
mididelight
06-28-2006, 11:15 AM
any reason why I the file is created but empty? it looks to me like I am not getting connected to the database, but i do not get any error messages. is there an mysql_error log somewhere?