How to backup and restore MySQL database?

by Stephen on September 25, 2008

You can backup your database automatically using this script

Here are the commands to manually do it via shell, given you have root privilege:

To dump the database onto a text file: mysqldump database_name > database_name.sql

To import the data into a database: mysql database_name < database_name.sql

Replace database_name with the name of your database.

{ 1 comment… read it below or add one }

linux tips November 21, 2008 at 6:39 am

Use the –opt switch to dumpo with all the options. Below is an example how to dump a database from a script and then packing it in bzip2. Especially usefull if your databses get bigger :-) .

/usr/bin/mysqldump –user root –password=”password” -opt $db | bzip2 -c > ../dump/db.sql.bz2

Reply

Leave a Comment

Previous post:

Next post: