Backing Up & Restoring a MySQL Database from the Command Line

A quick guide on using the MySQL CLI to manage your database backups.


Backup

Use MySQLDump to backup the database:

1
mysqldump -u [user_name] -p [database_name] > [file_name].sql

Where:

  • [user_name] is the name of your MySQL user
  • [database_name] is the name of your database
  • [file_name] is the name of your output file

Restore

Use the MySQL command line interface to restore from the backup you made previously:

1
mysql -u [user_name] -p [database_name] < [file_name].sql

Where:

  • [user_name] is the name of your MySQL user
  • [database_name] is the name of your database
  • [file_name] is the name of your input file