Backup and restore mysql database in linux

Not once you will need to make a backup and restore mysql database in linux.

Is quite easy to do this. For the backup you will need to use mysqldump.

Backup MySQL database to a file

To do a MySQL backup to a file you can use the following command:
You will use the sign greater than you must think the direction, from database to the backup file.

mysqldump -u root -p databasename > backupfilename.sql

And that’s it!

The parameters are:
-u root – the username to connect to the MySQL server
-p – means that the user has a password and you will be asked after you hit return. you can put the password directly in your command like this:
mysqldump -u root -p rootpassword databasename > backupfilename.sql
databasename – is the database you want to backup
backupfilename.sql – the filename of the file where the database backup will be stored.
If you write it like this it will save the backupfilename.sql in the current folder. If you want to save it to another folder just write /path/to/folder/backupfilename.sql

Restore MySQL database from a file

This is quite similar to backup but we will use mysql not mysqldump and sign is different < (to the database).

mysql -u root -p database < backupfilename.sql

If you need the full documentation of the mysqldump command – used to backup a database to a file – follow this link.

The official documentation for the mysql command – used to restore a database from a dump file – can be found here.
Official documentation for mysql backup

For more articles about linux use this link.