Back up a single database
msyqldump -u user -ppassword database > backup.sql
ADD DROP TABLE
Adding DROP TABLE statements appears to be the new default. If for some reason a system is not adding them, use:
mysqldump --add-drop-table -u user -ppassword database > backup.sql
Back up specified tables only
mysqldump -u [username] -p [password] [databasename] [table1 table2 ....] > backup.sql
Back up multiple databases
mysqldump -u user -ppassword --databases dbone dbtwo dbthree > multibackup.sql
Note, I am not yet sure what effect this will have on backing up specified tables.
Back up all databases
Use the --all-databases to back up all the databases a user has privileges to.
mysqldump -u user -ppassword --all-databases > alldatabases.sql
Back up only the database stucture
Use the --no-data option to back up database structures without their content.
mysqldump -u user -ppassword --no-data --databases dbone dbtwo dbthree > multibackup.sql
Compressing the Backup File on the Fly
The backup files can be piped to gzip or bzip2:
mysqldump -u user -ppassword --all-databases | bzip2 -c >databasebackup.sql.bz2
mysqldump -u user -ppassword --all-databases | gzip >databasebackup.sql.gz
This is probably a great practice as it reduced a 1.2M sql file to 312K.
