If you are a developer like me – you would have or might come across LAMP or LEMP stacks that does not have phpMyAdmin installed. So you have to rely on the command line interface to perform database related tasks. One the tasks you would find your self doing again and again is backing up or restoring the database. Here are few simple linux commands to backup and restore a database.
Export
mysqldump -u username -p database_name > dump.sql
to back up all databases
mysqldump -u username -p -all-databases > dump.sql
Restore
mysql -u username -p database_name < dump.sql
username is MySQL server username
database_name is the name of the database in MySQL server