Jaime Frutos Morales's blog

02/12/2009

Create and restore MySQL backups using mysqldump

Filed under: Databases, SysAdmin — acidborg @ 13:02

Description: “The mysqldump client is a backup program originally written by Igor Romanenko. It can be used to dump a database or a collection of databases for backup or transfer to another SQL server (not necessarily a MySQL server). The dump typically contains SQL statements to create the table, populate it, or both. However, mysqldump can also be used to generate files in CSV, other delimited text, or XML format.

To create a backup of a single database: mysqldump --opt -u database_admin_username -p database_name > database_name_backup.sql

To create a backup of all databases: mysqldump --opt -u database_admin_username -p --all-databases > all_databases_backup.sql

To restore a backup: mysql database_name -u database_admin_username -p < database_backup.sql

You might need to create the database you are restoring if you deleted it before:

mysql -u database_admin_username -p
CREATE DATABASE database_name;
QUIT

Advertisements

Blog at WordPress.com.

%d bloggers like this: