Monday, December 21, 2015

Backup and Restore MySQL Database

10:04 PM Posted by Unknown , No comments

The quick snippet of how backup and restore MySQL database using mysqldump:
Backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
Restore: # mysql -u root -p[root_password] [database_name] < dumpfilename.sql
Backup MySQL database 
1. Backup a single database:
# mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
2. Backup multiple databases:
# mysqldump -u root -p[root_password] --databases [database_1] [database_2] > database_1_and_2.sql
3. Backup all the databases:
# mysqldump -u root -p[root_password] --all-databases > /tmp/all-database.sql
4. Backup a specific table:
# mysqldump -u root -p[root_password] database_name table_name > /tmp/database_table.sql
Restore MySQL database 
1. Restore a database
# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
2. Backup a local database and restore to remote server using single command:
# mysqldump -u root -p[root_password] database_name | mysql -u root -p[root_password] --host=remote-server -C database_name1

0 comments:

Post a Comment