2012-09-13

Backup and restore MySQL database

Backup and restore MySQL database, please refer to http://webcheatsheet.com/sql/mysql_backup_restore.php

Backup:
mysqldump --opt -u [uname] -p[pass] [dbname] [tablename] > [backupfile.sql]

Backup multiple databases:
$ mysqldump -u [uname] -p[pass] --databases  [dbname1] [dbname2] ... > [backupfile.sql]
Backup all databases
$ mysqldump  -u [uname] -p[pass] --all-databases > [backupfile.sql]


Restore:
mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]

No comments: