Hi again!!I wanted to know that is it possible to backup the mysql database just by running query?I am trying to find out the code so that if a user clicks backup button, the whole database will be stored somewhere.

Recommended Answers

All 2 Replies

Something like that should work..

//DB connection

$tableName  = 'your_table';
$backupFile = 'backup/your_table.sql';
$query      = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = mysql_query($query);

//close DB connection

You can search for OUTFILE in http://dev.mysql.com/doc/refman/5.5/en/select.html :)

SELECT INTO OUTFILE does not export the database structure. Also it's a nightmare to handle outfile names with it.
For on-demand backup write a shell script which does the backup using the mysqldump program and make it accessible via your HTML interface.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.