I have a localhost MySQL server (wamp), and I have an online MySQL server. The thing is that I want to backup a table from the online server to my local server (copy data between existing tables).
I've tryed to use mysqldump
, but I have no result
<?php
exec("mysqldump --host=onlinehost --user=username --password=password dbname table \
| mysql --host=localhost --user=root --password= dblocalname");
?>
If you wanna take backup from online to local mysql server, you must open a port and define a static ip from your local modem. (you can fixed your ip from ISP).
<?php
$DBUSER="USERNAME";
$DBPASSWD="PASS";
$DATABASE="DBNAME";
$filename = "backup-" . date("d-m-Y") . ".sql.gz";
$mime = "application/x-gzip";
header( "Content-Type: " . $mime );
header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
$cmd = "mysqldump -u $DBUSER --password=$DBPASSWD $DATABASE | gzip --best";
passthru( $cmd );
echo ('Backup Complate !');
exit(0);
?>
way you can take dump of DB and down the dumped file. Example script above, create a dump and download it automatically from web browser:
way, you can use backup programs for online mysql to local db.
way you can create a windows service with crons for get backups from online database to local db.