MySql Database Backup & Restore - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

MySql Database Backup & Restore

Share This
Sometimes, you may want to keep a backup copy of the mysql database. There are several methods to back up a MySQL database, one of which is a command-line option. As you are working in mysql in your system, mysqldump utility is already installed.
This utility can be used to archive (make a copy) one or all databases of your system. In the following example, we will show how to backup a single mysql database. Two syntaxes are shown below, you may choose any one of them. 

#mysqldump --user=[user_name] --password=[password_of_the user] [database name] > [dump_file]
Or 
#mysqldump -u [user_name] -p [password_of_the user] [database name] > [dump_file] 

If you want to take a backup of all the databases of your system, instead of the name of the database, you have to write all databases as shown below. 

#mysqldump --user=[user name] --password=[password] all-databases > [dump file] 
Or 
#mysqldump -u [user name] -p [password] all-databases > [dump file] 

So, you have created a dump file of your mysql database, now we will discuss how to restore the backup. You may take the dump file to another system, where you want to restore the backup file. Simply run the following command and the database will be restored. 
mysql --user=[username] --password=[password] [database name] < [dump_file]

Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.