A simple and easy method for creating MySQL backups is to use the mysqldump command. This command will create a simple .sql file of an existing database, which can then be restored to any other empty MySQL database.
- Back up the database:-
[username] – A valid MySQL username.
[password] – A valid MySQL password for the user.
[database_name] – A valid Database name you want to take backup.[dump_file.sql] – The name of backup dump file you want to generate.
Sample command
- Backup more than one database
You can backup more than one database at the same time.
# mysqldump -u [user] -p –databases [database_name_1] [database_name_2] [database_name_n] > [filename].sql
- Backup of all databases
# mysqldump -u [user] -p –all-databases > [file_name].sql
- Restore the backup to a local database server: –
the mysql command will let you take the contents of a .sql file backup, and restore it directly to a database. This is the syntax for the command:
# mysql -u [username] –p[password] [database_name] < [dump_file.sql]
Sample command