How to backup and restore a MySQL database from the command line

Backing Up

To backup a MySQL database from the command line, use the mysqldump command and pip the output to a file. For example:

mysqldump -uroot -p name_of_database > backup_file.sql

Please note the file extension doesn’t have to be .sql but keeping it consistent like that will ease backup administration.

Restoring

To restore a MySQL database from the command line, use the mysql command and pipe the output from the backed up file.

mysql -uroot -p name_of_database < backup_file.sql

For example:

mysql -uroot -p Customers < mysql_backup_29_03_2019.sql

This command starts up MySQL and then pipes the backup file into the database that you specified.

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top