SQL to backup and restore MySQL database

You need to provide this object on a button click in my web application. Can be done with mysqldump, but for that I have to start an external process? (command line)

Is there a simple SQL query that allows us to back up and restore databases? (especially for MySQL)

+1


a source to share


3 answers


If you are using MySQL 6, you are fine - see http://dev.mysql.com/doc/refman/6.0/en/backup-database-restore.html . If you are using MySQL 5 things are not so rosy - you are probably better off using the mysqldump / external process approach.



+2


a source


mysqldump is probably your best bet. You can save table rows with SELECT ... INTO OUTFILE and reload them with LOAD DATA INFILE, but you must do it table by table and write the table schemas to another file for a full backup.



What's wrong with spawning a process to start mysqldump?

+1


a source


You can invoke external command line binaries here - this is a good introduction.

Or you run a couple of queries (like PHPMyAdmin) and store the result somewhere you want.

But there is no simple "one command" query for that.

0


a source







All Articles