mysqldump - Backing up your database
One of the support programs that comes with MySQL is an often overlooked program called mysqldump. With mysqldump you can easily dump a MySQL database to either CSV, XML, or a complete set of SQL instructions needed to recreate the database.
Normally you will call mysqldump using the following formats.
>$ mysqldump [options] –databases database_1 database_2
>$ mysqldump [options] –all-databases
We’ll go over the options in a minute, but for now notice the first command. This is the simplest way to dump a database. mysqldump will connect to the server and dump the contents of the database_name database. Use the –databases option followed by multiple database names if you want to backup more than on and the –all-databases if you want mysqldump to output all the databases you have permissions to view.
Saving to a file
mysqldump doesn’t normally save the output to a file, it just dumps it to screen. But that doesn’t do much good for backing up. Fortunately both Linux and DOS have an easy way to redirect the output from the screen to a file and that’s using the > character.
Note that using a > pointing to an existing file will overwrite that file. If you want to append the output to the file instead use a double >>
So, let’s say we want to save the output from mysqldump to the file ~/mydatabase.sql. We would use the following command.
For those of y’all using Windows, it would look something like this.
Pages: 1 2
Question, Comments...
Do you have more questions. Please either leave a comment below or join us in our new forum.