3

Anyone know of a PHP script that will clone an entire MySQL database to another on another server? As a sort of backup?

TechplexEngineer
  • 1,836
  • 2
  • 30
  • 48
  • I guess what I'm really looking for is something that will automatically detect teh number of tables, rows in each table, and then loop through them all, and do the appropriate create operation on a remote database.(Automatically) If so where do I get it, or ahow do I make phpMyAdmin do it? – TechplexEngineer Sep 19 '10 at 01:42
  • 1
    You could adjust this: http://www.electrictoolbox.com/php-script-backup-copy-mysql-table/ – miku Sep 19 '10 at 01:42

3 Answers3

6

phpMyAdmin does this very well. Of course, if you had shell access, try this instead:

mysqldump -u [username] -p [password] [database] > [filename]
Delan Azabani
  • 79,602
  • 28
  • 170
  • 210
6

You'd have your PHP script run (with e.g. the exec() or system() call) something like

mysqldump -q -C --databases mydatabase | mysql -C -h othermachine

Add the appropriate flags to these commands for specifying credentials, etc.

nos
  • 223,662
  • 58
  • 417
  • 506
1

You can refer this link. -

http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

This page is titled

MYSQL DUMP — A Database Backup Program

It contains all the details.

Hope this helps you.

Alpesh
  • 5,307
  • 2
  • 19
  • 19