How to Backup and Restore MySQL Database
In the previous article, I shared how to create a mysql database in Linux. Today, on this post, I’m going to guide you on how to backup and restore the mysql database.
Backup mysql database
Using below command:
mysqldump –opt -u [uname] -p [dbname] > [backupfile.sql]
Parameter:
- [uname]: user in a database
- [dbname]: database name
- [backupfile.sql]: backup filename
- [–opt]: mysqldump options
Example:
mysqldump -u root -p meterpreter > db_meterpreter.sql
Restore mysql database
Using below command:
mysql -u [uname] -p [dbname] < [backupfile.sql]
Parameter:
- [uname]: user in a database
- [dbname]: database name
- [backupfile.sql]: sql backup file
Example
mysql -u root -p meterpreter < db_meterpreter.sql