Friday, April 29, 2011

Is it possible using PHP to backup SQL without dependecies? If not, which is the best?

After a huge MySQL blunder on a production server (my fault, and yes I have learned), I am now looking at creating a dump of the MySQL database before I do a critical operation (about 15 queries to the db, insert/update/selects). I know phpMyAdmin can 'dump' the database to SQL queries, but I think this may be a feature of it, not a feature of MySQL?

So, is there a way to do this using MySQL, and if not (which I suspect), what would be the best way to dump the db to a file on the server on command? Preferably as a tarball of the whole DB in ready to import SQL format.

Thank You!

From stackoverflow
  • You are looking for the mysqldump function, I believe:

    mysqldump my_database > database.dump
    
  • MySQL dump will do it, and you can pipe it to gzip so it stores better:

    mysqldump --opt -Q -h[server] -u[username] -p[password] [dbname] | gzip > [file].sql.gz
    

    And to restore you unzip it and:

    mysql -h[server] -u[username] -p[password] [dbname] < [file].sql
    
  • I've used this for a few years now, why re-create the wheel :)

    http://worldcommunity.com/opensource

    alex : If the one line solution works, I'd hardly call that reinventing the wheel.
  • Another good route is to use something like sqlyog to automate backups. I run this on a local Windows machine I have to do backups of all my remote servers.

0 comments:

Post a Comment