Sameet
Sameet

Reputation: 2211

SQL command to backup and restore a MySQL database

Need to provide this facility on a button-click in my web application. Could be done using mysqldump, but for that I'd have to start an external process? (the command prompt)

Is there a simple SQL query that lets us backup and restore databases? (particularly for MySQL)

Upvotes: 1

Views: 4516

Answers (3)

Paul Dixon
Paul Dixon

Reputation: 301075

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

What's so bad about spawning a process to run mysqldump?

Upvotes: 1

MrFox
MrFox

Reputation: 3253

You can either call the external command line executables here is a nice intro to that.

Or you run a couple of queries (like PHPMyAdmin does) and store the result somewhere by your own.

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

Upvotes: 0

Alex Martelli
Alex Martelli

Reputation: 882681

If you use MySQL 6, you're fine -- see http://dev.mysql.com/doc/refman/6.0/en/backup-database-restore.html . If you're on MySQL 5, things aren't so rosy -- you're probably better off with the mysqldump / external process approach.

Upvotes: 2

Related Questions